this post was submitted on 15 Mar 2026
57 points (96.7% liked)
Rust
7855 readers
81 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
You have a few options here, but the easiest is to collect into a
Vec<char>, replace the character there, then do aString::from_iter(chars)to get it back as a string.You can also manipulate the original chars iterator directly through takes, skips, and so on and
collectit into a string, but that's more complicated.Also, "character" is such a complicated concept because unicode is not simple. If you can work directly with bytes though, you can convert the string to a
Vec<u8>(which is the underlying type forString), manipulate that directly, then doString::from_utf8(or the same method forstr) to convert it back to a string.Since OP will want to do a lot of character based operations for the hangman game, she could also consider using
Vec<char>as an internal representation everywhere and only converting intoStringfor display purposes.I agree, this makes the most sense. I was under the assumption they wanted to keep it as a
String, but your suggestion is a better way to approach the problem if they're able to do that.