Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subscriber: add Subscribe::boxed method #2026

Merged
merged 1 commit into from
Mar 26, 2022
Merged

Commits on Mar 25, 2022

  1. subscriber: add Subscribe::boxed method

    ## 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.
    hawkw committed Mar 25, 2022
    Configuration menu
    Copy the full SHA
    b0f62e0 View commit details
    Browse the repository at this point in the history