-
Notifications
You must be signed in to change notification settings - Fork 743
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
subscriber: add
Subscribe::boxed
method (#2026)
## Motivation PR #2023 made the `impl Subscribe` for boxed `dyn Subscribe` 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 subscriber's type, it's necessary to add a type annotation like this: ```rust let boxed_subscriber: Box<dyn Subscribe<_> + Send + Sync + 'static> = Box::new(some_subscriber); ``` Because the trait object includes `Send + Sync + 'static`, this is a bit wordy to type out. ## Solution This commit adds a `Subscribe::boxed` method that takes `Self` and boxes it as a type-erased `dyn Subscribe` trait object. This can then be chained after a a chain of subscriber builder methods. Because the `boxed` method _explicitly_ returns a `dyn Subscribe + ...` trait object, it's not necessary to use a wordy type annotation when using this method.
- Loading branch information
Showing
1 changed file
with
129 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