Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
subscriber: forward
Filtered::downcast_raw
to wrapped Layer (tokio-…
…rs#1619) ## Motivation I'm trying to implement a `Layer` that has something very similar to tracing-error's [`WithContext`](https://github.com/tokio-rs/tracing/blob/66cd79f72af5ebcb6f21a1017b6ce33bea05558d/tracing-error/src/layer.rs#L32) to support erasing types and getting access to the current span's state. To do that, I implement `Layer::downcast_raw` in [the same way that tracing-error does](https://github.com/tokio-rs/tracing/blob/66cd79f72af5ebcb6f21a1017b6ce33bea05558d/tracing-error/src/layer.rs#L55-L63). This works great when the layer is not filtered. However, once I filter the layer ```rust let filter = tracing_subscriber::filter::Targets::new().with_default(tracing::Level::INFO); let layer = MyLayer::new(); tracing_subscriber::registry().with(layer.with_filter(filter)).init(); ``` I'm not able to get a `WithContext` instance anymore, because `Filtered` [handles `downcast_raw`, and doesn't forward it](https://github.com/tokio-rs/tracing/blob/66cd79f72af5ebcb6f21a1017b6ce33bea05558d/tracing-subscriber/src/filter/layer_filters.rs#L379-L391) to `MyLayer::downcast_raw`. ## Solution If `Filtered::downcast_raw` does not know how to handle the given type, forward it to the wrapped layer's `Layer::downcast_raw` implementation. Fixes tokio-rs#1618
- Loading branch information