forked from tokio-rs/tracing
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
subscriber: add
Layer::boxed
method (tokio-rs#2026)
## Motivation PR tokio-rs#2023 made the `impl Layer` for boxed `dyn Layer` trait objects actually be useful. One minor annoyance when working with boxed trait objects is that, in some cases, in order to use `Box::new` to erase a `Layer`'s type, it's necessary to add a type annotation like this: ```rust let boxed_layer: Box<dyn Layer<_> + Send + Sync + 'static> = Box::new(some_layer); ``` Because the trait object includes `Send + Sync + 'static`, this is a bit wordy to type out. ## Solution This commit adds a `Layer::boxed` method that takes `Self` and boxes it as a type-erased `dyn Layer` trait object. This can then be chained after a a chain of layer builder methods. Because the `boxed` method _explicitly_ returns a `dyn Layer<_> + ...` trait object, it's not necessary to use a wordy type annotation when using this method.
- Loading branch information
Showing
1 changed file
with
128 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters