-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Implement size_hint for several unicode-based iterators. #50208
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
Implement size_hint for several unicode-based iterators. #50208
Conversation
This continues work on issue rust-lang#49205. This PR also implements ExactSizeIterator and FusedIterator where they make sense.
r? @shepmaster (rust_highfive has picked a reviewer for you, use r? to override) |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
|
r? @scottmcm |
@shepmaster As far as I know, I don't actually have bors permissions, so I don't think I should be assigned? |
@scottmcm I can delegate permissions to you if you'd like, but I can also pick someone else 😉 Which would you prefer? |
src/libcore/str/lossy.rs
Outdated
} | ||
|
||
fn size_hint(&self) -> (usize, Option<usize>) { | ||
(0, Some(self.source.len())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea here is that we could have 0 due to an error, and self.source.len()
if every character is ASCII?
Side note: I wonder if we should have small comments on all these describing the logic and rationale behind them, just like we encourage for unsafe
blocks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's the idea. I'll add a comment about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks overall fine, though of course the tidy errors need to be fixed.
But it's adding insta-stable impls, so I think it needs @rust-lang/libs eyes on it.
} | ||
|
||
#[stable(feature = "fused", since = "1.26.0")] | ||
impl FusedIterator for ToUppercase {} | ||
|
||
impl ExactSizeIterator for ToUppercase {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like the line above it, this should have an attribute, something like
#[stable(feature = "case_mapping_len", since = "1.27.0")]
CaseMappingIter::One(_) => { | ||
(1, Some(1)) | ||
} | ||
CaseMappingIter::Zero => (0, Some(0)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I'm confident this is correct, I think it'd still be good to have a test to pin the behaviour; a bunch of things like assert_eq!('a'.to_lowercase().len(), 1)
, perhaps.
@@ -177,6 +184,8 @@ impl fmt::Display for Utf8Lossy { | |||
} | |||
} | |||
|
|||
impl<'a> FusedIterator for Utf8LossyChunksIter<'a> {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there tests that verify this? (There might be something already; I dunno.)
If new insta-stable impls are added, can tests also be added to ensure that they're correct? Otherwise would it be possible to leave them to a future PR? |
Ping from triage, @Phlosioneer ! You've got some more feedback to address. |
Thank you for this PR @Phlosioneer! Unfortunately we haven't heard from you on this in a while, so I'm closing the PR to keep things tidy. Don't worry though, if you'll have time again in the future please reopen this PR, we'll be happy to review it again! |
This continues work on issue #49205.
This PR also implements ExactSizeIterator and FusedIterator where
they make sense.
I didn't know what to put for the issue number when making the [unstable] annotation, so I put 0 as a placeholder.