How to convert iterator of chars to String?

.collect() is generic in what collection it produces, and it can produce the String for you!

let s = "abc".chars().collect::<String>();

The trait FromIterator determines which elements you can collect into which kind of collection, and among the implementors you can find String twice:

impl FromIterator<char> for String
impl<'a> FromIterator<&'a str> for String

Both iterators of char and of &str can be collected to String.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)