Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add FromIterator impls for ascii::Chars to Strings #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

Open
yotamofek wants to merge 1 commit into rust-lang:master
base: master
Choose a base branch
Loading
from yotamofek:pr/library/from-iter-char-string

Conversation

Copy link
Contributor

@yotamofek yotamofek commented May 23, 2025

Wanted to collect ascii chars into a String 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 corresponding FromIterator<&Char> impl, because there's no existing impl for FromIterator<&char>, but that might be oversight too.

cc #110998

Copy link
Collaborator

rustbot commented May 23, 2025

r? @joboet

rustbot has assigned @joboet.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels May 23, 2025

This comment has been minimized.

@yotamofek yotamofek force-pushed the pr/library/from-iter-char-string branch from 4e9a021 to 8365332 Compare May 23, 2025 13:51
Copy link
Member

@joboet joboet left a 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

yotamofek reacted with thumbs up emoji
Comment on lines 2380 to 2382
let mut buf = String::new();
buf.extend(iter);
buf
Copy link
Member

@joboet joboet May 23, 2025
edited
Loading

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

Suggested change
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) }

Copy link
Contributor Author

@yotamofek yotamofek May 23, 2025

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!

Comment on lines 2390 to 2392
let mut buf = String::new();
buf.extend(iter);
buf
Copy link
Member

Choose a reason for hiding this comment

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

(likewise)

@rustbot rustbot added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label May 23, 2025
@rustbot rustbot assigned joshtriplett and unassigned joboet May 23, 2025
Copy link
Contributor Author

Hey, @joshtriplett , friendly ping :) I'd love to get this looked at! Thank you 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@joboet joboet joboet left review comments

Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /