1 hour ago · 6 min read1146 words · Tech · hide

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 If we derive Debug for an enum, we can format a variant as a string. Note that debug output isn’t a stable serialization format, so this just happens to work for this particular string. #[allow(non_camel_case_types)] #[derive(Debug)] enum Mascot { ferris, } let ferris = format!("{:?}", Mascot::ferris); Use a CString This is another very obvious one: we can use CString to create a string with a NUL terminator,…

Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town