What's the toughest thing in Rust to learn? Lifetimes? Or these Box/Arc/Rc/Pin etc?
What's the toughest thing in Rust to learn? Lifetimes? Or these Box/Arc/Rc/Pin etc?
For me the actual toughest thing to learn were procedural macros, and the reason for that is because actually implementing them is more on the niche side of programming compared to using them, so most "learning Rust" resources just hand wave them away, and their usage is so special cased that all the limited learning resources around them target specific niche use cases that might not be what you in particular would use them for.
I think if you are coming from systems programming languages, or even if managed, languages that have explicit notion of stack and heap, Rust concepts are easier to learn, as they are quite similar.
What is probably more complicated to learn, and me as polyglot dev with limited brain capacity, are the ways of async Rust, Pin and co.
With that said, of course you'd eventually come across those things, especially as you try to troubleshoot your own code and go down the Bevy internals stack, and it's generally helpful to know the language you use for your game :) But I don't think it's a requirement to know those things before you get your feet wet.
Edit: I maybe realize now that parent didn't actually ask for "Rust+Bevy answer" but just Rust so I might be the one who tuned my answer incorrectly :|
is this directly enough?
different people struggle with different things. your existing experience is a major factor. there are a lot of concepts in rust that you may have already figured out in another language.
personally, i started learning rust two years after i started programming. at that point i had basic experience with c, c++, and some assembly.
i struggled with pretty much everything. i recall traits being particularly confusing. i’m not sure i fully got them until i messed with typeclasses in haskell at some later point.
but, honestly, i don’t remember struggling too much with lifetimes. i think the compiler is pretty good at suggesting fixes for common issues. i think it was helpful that i knew what a pointer was and had debugged segfaults. also, i didn’t really have an existing way of structuring programs that i was trying to reconcile with rust.
Box, Arc, and Rc you’ll figure out as you need them. you can think of them as tools which let you escape lifetimes.
Pin you won’t need to think about for a very long time [0]. You should check out my guide [1] if you’re interested though :). There are many others.
[0]: unless you’re the guy i’ve tasked with fully understanding FuturesUnordered as his very first introduction to Rust, lmao.
[1]: https://github.com/soooch/async-intuition/blob/main/src/pin_...
All they do is guarantee that a type has methods A,B,C available.
What might be slightly confusing are trait bounds on generics. They are kind of like traits themselves but not exactly. They implicitly say "this generic parameter must make methods A, B, C available via Trait X".
Very few things are truly intuitive, they just happen to be similar to other things you've done and so you've got a step up on understanding them. Really good software engineers tend to be constantly playing with things outside their usual domain and so have broader range of concepts they can reach for when the time comes.
all i wanted was to add a new method i could call in the same way as all the methods on Iterator (map, filter, etc.). and was suddenly confronted with `impl Trait2 for T where T: Trait1`. which makes perfect sense now. but at the time was unparseable.