80

I recently started learning rust, and I was ready for one hell of a fight. I heard all those horror Storys about the compiler complaining about every single detail and that developing rust means having a constant fight with the compiler about seemingly irrelevant things. However, so far I have to tell, that while its somewhat true, that the compiler is somewhat picky, it is incredibly helpful. Never before have I seen such good and helpful compiler messages. It not only says what you did wrong, but also gives direct help on what to do to fix your code. I also really like, that it gives you direct references to the rust book in the compiler messages.

Prior to starting my journey with rust I did quite a lot of python, some C and some bash and their interpreter/compiler messages are nothing when comparing them with rust. Especially the bash error messages are awful if you do not know what they mean and how to fix them.

top 24 comments
sorted by: hot top controversial new old
[-] DrFunkenstein@sh.itjust.works 25 points 1 day ago

It's the only compiler I've ever seen alert you if you're using a Greek question mark ; instead of an actual semicolon ;

[-] TechnoCat@piefed.social 10 points 1 day ago

I sometimes can't believe how helpful rustc is.

[-] FizzyOrange@programming.dev 13 points 1 day ago

Yeah I think the reputation was probably deserved early in Rust's life, but as time has gone on it has gotten a lot easier to write, especially with the non-lexical lifetimes update 3 years ago.

[-] robinm@fosstodon.org 1 points 9 hours ago
[-] FizzyOrange@programming.dev 1 points 2 hours ago

Yeah I feel like it was more than 3 years ago but I guess it's been a long 3 years!

https://blog.rust-lang.org/2022/08/05/nll-by-default/

[-] SorteKanin@feddit.dk 13 points 1 day ago

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.

[-] cows_are_underrated@feddit.org 2 points 1 day ago

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`___`

[-] TehPers@beehaw.org 8 points 1 day ago

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).

You have a few options here, but the easiest is to collect into a Vec<char>, replace the character there, then do a String::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 collect it 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 for String), manipulate that directly, then do String::from_utf8 (or the same method for str) to convert it back to a string.

[-] semi@lemmy.ml 5 points 1 day ago* (last edited 1 day ago)

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 into String for display purposes.

[-] TehPers@beehaw.org 4 points 1 day ago

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.

[-] SorteKanin@feddit.dk 3 points 1 day ago

Others have already pointed out the issue - in Rust, String is UTF-8 encoded and therefore characters are variable length. So you can't just change a character in a string, as it may not fit (e.g. replacing 'a' with '🙂' would lead to trouble).

You can do what the others suggest, but honestly for a game like hangman, I'd suggest you just work directly with chars and don't use any string. As in, just use a Vec instead of a string. Then you can freely change characters based on index, but this representation uses more memory than a typical String. But this won't matter for your use case.

[-] cows_are_underrated@feddit.org 3 points 1 day ago

Working with a vector directly would probably be easier, however for a learning experience this was actually great. I read through quite a lot of documentation trying to figure out how I achieve what I want. Might reimplement it with vectors later just for the learning experience.

[-] Miaou@jlai.lu 4 points 1 day ago

This is simply not possible in rust, because strings are utf-8, so the size of a single character can vary. I think there might be a class for ASCII strings, but otherwise you can just use Vev and then convert to string

[-] glynwolf@tiggi.es 1 points 1 day ago

@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>();

[-] cows_are_underrated@feddit.org 1 points 1 day ago

That worked. Thanks :3

[-] vk6flab@lemmy.radio 5 points 1 day ago

For bash scripting, shellcheck is your missing ingredient.

[-] FizzyOrange@programming.dev 8 points 1 day ago

It's better than nothing but it really only drags Bash from "your code is definitely horribly broken" to "your code is probably broken". Nothing like Rust!

[-] vk6flab@lemmy.radio 3 points 1 day ago

Anyone here remember Pascal and its successor, Modula-2?

[-] glynwolf@tiggi.es 2 points 1 day ago

@vk6flab Pascal was my learning language!

[-] vk6flab@lemmy.radio 1 points 1 day ago

For me it was 6502 assembly and Applesoft BASIC, followed by Commodore BASIC :)

[-] boonhet@sopuli.xyz 1 points 1 day ago

No, but if you want to write Delphi for a living, I can hook you up.

[-] solrize@lemmy.ml 4 points 1 day ago* (last edited 1 day ago)

Haskell is also extremely picky about programs though GHC's error messages are notoriously confusing. Basically they say "error at line 123" with a bunch of incomprehensible spew saying what the error is. So you ignore the spew, look at line 123, and squint til you figure out what is wrong. In practice that method actually works once you get used to it. C++ is kind of similar IME.

You might also give Ada a try. Its goals overlap Rust's and I'd like to have some familiarity with both.

Based on your mentions of Python and bash, I'd say spend more time on languages with serious type systems. Rust, Haskell, Ada, ML, and maybe pointy headed languages beyond Haskell.

[-] cows_are_underrated@feddit.org 2 points 1 day ago

The lack of a strict type system is, what drives me away from python (there is a lot of other stuff I also dont like, but its lack of a type systems is one of the biggest reasons). My first language was Java, which I learned during highschool and while I thought that the strict type system was annoying, working with Python made me realise how much I hate not having a strict type system. In every god damn function you have to manually check for the type you received to make sure everything works as expected.

this post was submitted on 15 Mar 2026
80 points (97.6% liked)

Rust

7860 readers
48 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

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