Answer: How do I convert from a char array [char; N] to a string slice &str?



This content originally appeared on DEV Community and was authored by Towry

You can’t without some allocation, which means you will end up with a String.

let s2: String = s.iter().collect();

The problem is that strings in Rust are not collections of chars, they are UTF-8, which is an encoding without a fixed size per character.

For example, the array…


This content originally appeared on DEV Community and was authored by Towry