Is there a succinct way to convert a char
to a String
in Rust other than:
let mut s = String::new();
s.push('c');
Is there a succinct way to convert a char
to a String
in Rust other than:
let mut s = String::new();
s.push('c');
You use the to_string()
method:
'c'.to_string()
Since Rust 1.46, String
implements From<char>
, so you can alternatively use:
String::from('c')
or, with type inference,
'c'.into()