Add a count method to Source #329

Merged
KodrAus merged 2 commits from feat/source-count into master 2019-04-29 21:16:51 -05:00
KodrAus commented 2019-04-29 01:31:46 -05:00 (Migrated from github.com)

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.

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 commented 2019-04-29 01:32:52 -05:00 (Migrated from github.com)

r? @Thomasdezeeuw

r? @Thomasdezeeuw
Thomasdezeeuw (Migrated from github.com) approved these changes 2019-04-29 04:08:07 -05:00
Thomasdezeeuw (Migrated from github.com) left a comment

Looks good to me.

Looks good to me.
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-rust-lang/log!329
No description provided.