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

Commit 8365332

Browse files
Add FromIterator impls for ascii::Chars to Strings
1 parent 52bf0cf commit 8365332

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

‎library/alloc/src/string.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,6 +2373,26 @@ impl<'a> FromIterator<Cow<'a, str>> for String {
23732373
}
23742374
}
23752375

2376+
#[cfg(not(no_global_oom_handling))]
2377+
#[unstable(feature = "ascii_char", issue = "110998")]
2378+
impl FromIterator<core::ascii::Char> for String {
2379+
fn from_iter<T: IntoIterator<Item = core::ascii::Char>>(iter: T) -> Self {
2380+
let mut buf = String::new();
2381+
buf.extend(iter);
2382+
buf
2383+
}
2384+
}
2385+
2386+
#[cfg(not(no_global_oom_handling))]
2387+
#[unstable(feature = "ascii_char", issue = "110998")]
2388+
impl<'a> FromIterator<&'a core::ascii::Char> for String {
2389+
fn from_iter<T: IntoIterator<Item = &'a core::ascii::Char>>(iter: T) -> Self {
2390+
let mut buf = String::new();
2391+
buf.extend(iter);
2392+
buf
2393+
}
2394+
}
2395+
23762396
#[cfg(not(no_global_oom_handling))]
23772397
#[stable(feature = "rust1", since = "1.0.0")]
23782398
impl Extend<char> for String {
@@ -3200,6 +3220,14 @@ impl<'a> FromIterator<String> for Cow<'a, str> {
32003220
}
32013221
}
32023222

3223+
#[cfg(not(no_global_oom_handling))]
3224+
#[unstable(feature = "ascii_char", issue = "110998")]
3225+
impl<'a> FromIterator<core::ascii::Char> for Cow<'a, str> {
3226+
fn from_iter<T: IntoIterator<Item = core::ascii::Char>>(it: T) -> Self {
3227+
Cow::Owned(FromIterator::from_iter(it))
3228+
}
3229+
}
3230+
32033231
#[stable(feature = "from_string_for_vec_u8", since = "1.14.0")]
32043232
impl From<String> for Vec<u8> {
32053233
/// Converts the given [`String`] to a vector [`Vec`] that holds values of type [`u8`].

‎tests/ui/suggestions/semi-suggestion-when-stmt-and-expr-span-equal.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ LL | .collect::<String>();
2121
|
2222
= help: the trait `FromIterator<()>` is not implemented for `String`
2323
= help: the following other types implement trait `FromIterator<A>`:
24+
`String` implements `FromIterator<&Char>`
2425
`String` implements `FromIterator<&char>`
2526
`String` implements `FromIterator<&str>`
2627
`String` implements `FromIterator<Box<str, A>>`
28+
`String` implements `FromIterator<Char>`
2729
`String` implements `FromIterator<Cow<'_, str>>`
2830
`String` implements `FromIterator<String>`
2931
`String` implements `FromIterator<char>`

0 commit comments

Comments
(0)

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