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 Targets::targets method to iterate directives #1574

Merged
merged 7 commits into from
Sep 18, 2021
Merged

subscriber: add Targets::targets method to iterate directives #1574

merged 7 commits into from
Sep 18, 2021

Commits on Sep 17, 2021

  1. subscriber: implement IntoIterator for &Targets

    There's currently no way to get the registered directives from a
    `Targets` instance, which is a barrier to some use-cases such as
    combining user-supplied directives with application-supplied defaults.
    
    This commit implements `IntoIterator` for `&Targets`. The returned
    iterator will yield `(&str, LevelFilter)` pairs, on for each directive
    (excluding the default level, whose `target` is `None`). Additionally,
    an `iter` method has been added to `Targets` as a convenience for
    obtaining an iterator for method chaining.
    
    Items are yielded as per the underlying `DirectiveSet::iter`, which
    would yield items in specifity order (as constructed by
    `DirectiveSet::add`). However, the order has been left explicitly
    undefined in the documentation for `Targets::targets` on the basis that
    this is an implementation detail that may change.
    
    In order to namespace the `Iter` type nicely, the
    `tracing_subscriber::filter::targets` module has been made public, along
    with some nominal documentation. The `filter` module continues to
    re-export the `Targets` type so this is not a breaking change.
    Chris Connelly authored and connec committed Sep 17, 2021
    Configuration menu
    Copy the full SHA
    2abb38c View commit details
    Browse the repository at this point in the history
  2. subscriber: implement IntoIterator for Targets

    This adds an owning iterator implementation for `Targets`. The returned
    `IntoIter` type is hosted in `filter::targets` alongside the existing
    `Iter` type.
    
    Due to the underlying directive storage being determined based on
    features, `IntoIterator` has also been implemented on the internal
    `DirectiveSet` type to keep the feature handling within that module.
    connec committed Sep 17, 2021
    Configuration menu
    Copy the full SHA
    992ee96 View commit details
    Browse the repository at this point in the history

Commits on Sep 18, 2021

  1. Configuration menu
    Copy the full SHA
    0d589ae View commit details
    Browse the repository at this point in the history
  2. subscriber: Add targets iterator constructors

    This moves the logic of creating the inner iterator into a constructor
    function on the iterators themselves. This brings the type definition
    and implementation closer together.
    
    The implementation has been changed to use closures, since they don't
    capture and can be converted to `fn()`. This avoids repeating the
    signature.
    connec committed Sep 18, 2021
    Configuration menu
    Copy the full SHA
    6e80a9f View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    d8cdc44 View commit details
    Browse the repository at this point in the history
  4. subscriber: import FilterMap in targets

    This cuts down some noise, since we use it twice.
    connec committed Sep 18, 2021
    Configuration menu
    Copy the full SHA
    59a816e View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    98153a1 View commit details
    Browse the repository at this point in the history