Add a Source::get method for finding a single value#335
Merged
Conversation
29 tasks
EFanZh
pushed a commit
to EFanZh/log
that referenced
this pull request
Jul 23, 2023
Co-authored-by: Félix Saparelli <felix@passcod.name>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.