83
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
this post was submitted on 15 Mar 2026
83 points (97.7% liked)
Rust
7863 readers
8 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
Definitely! The only other language where I felt the compiler actually helped me was Haskell. C and C++ just go like "something is fucked, you figure it out".
I think the learning curve exists but it has been vastly overestimated by the rumours. I have many years of experience with Rust now, just ask if you are unsure of anything. Feel free to tag me in any post or PM me, then I'll definitely see it.
Currently I am trying to figure out how to access and change single characters in a string (I am coding a basic version of hangman to get used to working with rust). The main problem I have is, that I can not figure out how to change the value of a single character in a string based on its index. I have a string (that has the same length as my "word to guess") containing only underscores and whenever the user correctly guesses a character I want to replace the underscores by the guessed character to show the user how much he has guessed so far. I was able to turn the string into a char iterator, but I could not figure out how to change elements of said iterator (this can be seen at line 55).
The code is here: https://pastebin.com/kfSYWT42`___`
@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