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

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

Jul 13 ’16

23


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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » Answer: How do I convert from a char array [char; N] to a string slice &str?." Towry | Sciencx - Saturday July 20, 2024, https://www.scien.cx/2024/07/20/answer-how-do-i-convert-from-a-char-array-char-n-to-a-string-slice-str/
HARVARD
Towry | Sciencx Saturday July 20, 2024 » Answer: How do I convert from a char array [char; N] to a string slice &str?., viewed ,<https://www.scien.cx/2024/07/20/answer-how-do-i-convert-from-a-char-array-char-n-to-a-string-slice-str/>
VANCOUVER
Towry | Sciencx - » Answer: How do I convert from a char array [char; N] to a string slice &str?. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/07/20/answer-how-do-i-convert-from-a-char-array-char-n-to-a-string-slice-str/
CHICAGO
" » Answer: How do I convert from a char array [char; N] to a string slice &str?." Towry | Sciencx - Accessed . https://www.scien.cx/2024/07/20/answer-how-do-i-convert-from-a-char-array-char-n-to-a-string-slice-str/
IEEE
" » Answer: How do I convert from a char array [char; N] to a string slice &str?." Towry | Sciencx [Online]. Available: https://www.scien.cx/2024/07/20/answer-how-do-i-convert-from-a-char-array-char-n-to-a-string-slice-str/. [Accessed: ]
rf:citation
» Answer: How do I convert from a char array [char; N] to a string slice &str? | Towry | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.