endler.dev · 29d · discuss
I’m on my way back from RustLab 2026, where I gave a lightning talk about all the ways to create a String in Rust that don’t involve String::new. The talks were not recorded, so I decided to write it up as a blog post. Collect Some Characters One of the most obvious ways to create a string without calling String::new is to collect some characters into a string: let ferris: String = ['f', 'e', 'r', 'r', 'i', 's'] .into_iter() .collect(); Alternatively, you can start with the UTF-8 bytes: let ferris = String::from_utf8(vec![102, 101, 114, 114, 105, 115]) .unwrap(); Derive Debug...