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

Add a count method to Source #329

Merged
merged 2 commits into from
Apr 30, 2019
Merged

Conversation

KodrAus
Copy link
Contributor

@KodrAus KodrAus commented Apr 29, 2019

Adds a Source::count(&self) -> usize method to figure out how many key-value pairs to expect.

I've also tried to clarify the expectation that subsequent calls to Source::visit will yield the same key-value pairs unless the visitor fails. A buggy Source::visit with the default implementation of count may yield a different number of key-value pairs. Given that, we could make the method something like Source::size_hint(&self) -> Option<usize> instead, but I think the fundamental requirement that Source::visit passes the same pairs to the visitor unless the visitor itself fails is reasonable and lets us add more useful methods like for_each that don't have to return results. The reason visit itself is fallible is so that a formatting or serialization error can be passed upstream for a logging framework to surface in some way.

@KodrAus
Copy link
Contributor Author

KodrAus commented Apr 29, 2019

r? @Thomasdezeeuw

Copy link
Collaborator

@Thomasdezeeuw Thomasdezeeuw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@KodrAus KodrAus merged commit cd690d1 into rust-lang:master Apr 30, 2019
@KodrAus KodrAus deleted the feat/source-count branch April 30, 2019 02:16
EFanZh pushed a commit to EFanZh/log that referenced this pull request Jul 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants