this post was submitted on 15 Mar 2026
70 points (97.3% liked)
Rust
7855 readers
95 users here now
Welcome to the Rust community! This is a place to discuss about the Rust programming language.
Wormhole
Credits
- The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
@cows_are_underrated The simplest way I’ve found to do that is to convert the string into a Vec<char>. UTF-8 strings aren’t optimized for random access because of multi-byte chars.
To array of chars:
let c = s.chars().collect::<Vec<char>>();
And back to string:
let s = c.into_iter().collect::<String>();
That worked. Thanks :3