DEV Community

Towry
Towry

Posted on

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

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…

Top comments (0)