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 char
s, 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
Towry | Sciencx (2024-07-20T04:54:20+00:00) Answer: How do I convert from a char array [char; N] to a string slice &str?. Retrieved from https://www.scien.cx/2024/07/20/answer-how-do-i-convert-from-a-char-array-char-n-to-a-string-slice-str/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.