Add a Source::get method for finding a single value #335
No reviewers
Labels
No labels
bug
duplicate
easy
enhancement
help wanted
invalid
question
rfc
structured-logging
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-rust-lang/log!335
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/source-get"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Part of #149
Adds
gettoSourcefor fetching a single value:It's useful for cases where you want to find 'well-known' key values like timestamps, errors, trace ids etc.
The method needs to be object-safe, so it takes a concrete
Keyinstead of a generic type. It could take a&dyn ToKeyinstead, which could have nicer ergonomics, but I opted for the simpler API to start with.The method has a default implementation that has a O(N) cost. It will always look at all key-value pairs. Implementations for types like maps or concrete structs can override this to be more efficient. For implementations that we own we could use the
Resultto early return when a match is found instead of continuing to look for a match.I've also refactored the test utilities we're using to check implementations of
Valueso they can be used in other tests too.