-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add FromIterator
impls for ascii::Char
s to String
s
#141445
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
base: master
Are you sure you want to change the base?
Add FromIterator
impls for ascii::Char
s to String
s
#141445
Conversation
This comment has been minimized.
This comment has been minimized.
4e9a021
to
8365332
Compare
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.
Makes complete sense to me! This will need T-libs-api approval though...
Implementation-wise, I think it'd be good to go through Vec
's FromIterator
implementation. That way we get to take advantage of all of its nice specialisations...
r? libs-api
library/alloc/src/string.rs
Outdated
let mut buf = String::new(); | ||
buf.extend(iter); | ||
buf |
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.
Something along the lines of
let mut buf = String::new(); | |
buf.extend(iter); | |
buf | |
let mut buf = iter.into_iter().map(Char::to_u8).collect(); | |
unsafe { String::from_utf8_unchecked(buf) } |
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.
Huh, that's clever, thanks!
library/alloc/src/string.rs
Outdated
let mut buf = String::new(); | ||
buf.extend(iter); | ||
buf |
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.
(likewise)
8365332
to
8569bb2
Compare
Wanted to
collect
ascii chars into aString
while working on #141369 , and was surprised these impls don't exist. Seems to me to be simply oversight.BTW, I only added
impl FromIterator<ascii::Char> for Cow<'_, str>
, without a correspondingFromIterator<&Char>
impl, because there's no existing impl forFromIterator<&char>
, but that might be oversight too.cc #110998