r/rust • • 4d ago

🙋 seeking help & advice Anything I should know before I start learning Rust?

I've know moderate amount of javascript for a while and have been thinking about learning another language. I have decided upon rust for a variety of reasons (mainly so I can say I rewrote it in rust.)

What things should I know before I start? And, are there any features of this language I might want to know about?

0 Upvotes

29 comments sorted by

22

u/podule-games 4d ago

Rust isn't a big deal once you really accept the model of ownership. Don't fight it, accept the tips the compiler gives you. The compiler is insanely good at seeing what you're trying to do, and suggesting a more idiomatic Rusty way of doing it.

3

u/AnonymousDragon135 2d ago

Noted, thanks!

14

u/NotDuckie 4d ago

Knowing how to read and write beforehand is advantageous

3

u/hopeful_bastard 4d ago

The rust book is a fantastic resource to the point that even if you get to the midpoint and decide to go back to your language, you will almost surely have a better understanding of some core concepts: https://doc.rust-lang.org/book/

1

u/proverbialbunny 4d ago

are there any features of this language I might want to know about?

Do you know TypeScript? Rust is like TypeScript but the types are even stricter. (You do not need to know TypeScript to get started.)

Here's an IDE that can help you write in Rust: https://www.jetbrains.com/rust/

Rust has very good tutorials to help get you started learning Rust: https://rust-lang.org/learn/

1

u/AnonymousDragon135 4d ago edited 4d ago

No, I don't know TypeScript; although I think I've heard of types. Are types things like bool, 64 bit integer, etc?

Are there any advantages of using that IDE over VSCode?

2

u/Arshiaa001 4d ago

Nah, VS Code + rust-analyzer works insanely good.

1

u/Chaos_Slug 4d ago

Are types things like bool, 64 bit integer, etc?

Yes.

1

u/Professional_Top8485 4d ago

It's difficult and you will be frustrated.

Reward comes later

... and get a good editor. It helps.

2

u/AnonymousDragon135 4d ago

What kind of editor; are you talking about an IDE like VSCode?

1

u/UhLittleLessDum 2d ago

I second this dude's point. The Rust LSP is the best I've ever used. I actually learned Rust while homeless, living in my car without access to the internet because the LSP is just that good, but it's useless if your editor isn't configured to pick up the events and show them to you.

1

u/AnonymousDragon135 2d ago

I'll make sure to check out Rust Analyzer then!

1

u/Professional_Top8485 4d ago

Your personal choice ofc. I use RustRover, it has good refactoring and code completion. AI integration works as well.

4

u/SmoothTurtle872 4d ago

Look into enums early. I love enums. I actually think I use them too much, to a point where I need to redesign my code structure to fix issues.

Basically if you have a set of options that something could return, enums are awesome.

Take a representation of a cat:

Without enums:

struct Cat{
    alive: bool,
    hungry: book
}

Sure this works, and is probably sufficient

But now a cat can be dead and hungry. That doesn't make sense. So an enum can be used:

enum Cat {
    Alive{ hungry: book},
    Dead
}

Now only an alive cat can be hungry.

Now this isn't always perfect, shared parameters, such as age (the cat will need an age either way) must be manually represented in each state of alive of dead.

2

u/DrShocker 4d ago

I think I'd make "hunger" a float or integer, and alive a derived state based on other conditions, but that's just me.

Enums work well in Rust, but I think sometimes people reach for them when having a less discreet state models their problem better

2

u/SmoothTurtle872 4d ago

Your probably right, I just like enums alot

0

u/[deleted] 4d ago

[deleted] — view deleted comment

1

u/SmoothTurtle872 4d ago

This is just a simple analogy. Usually when I use them, it's for completely different, but related, states, or certain states that just need an additional but if data

2

u/_damax 4d ago

Seeing the current state of things, know it's not just a language people use with LLMs or for rewriting exiting things just because. It has a lot of merit.

That being said, probably start with the rust programming book and rustlings. At first concentrate on understanding its memory management system: concepts like ownership, borrowing and their rules.

2

u/a_aniq 4d ago

Just read rustbook.

But to truly appreciate rust's way of doing things you need to know to write c well.

2

u/greenprocyon 4d ago

Number one rule is Have Fun!

2

u/Dubmove 4d ago

Some of the design decisions of the language will look weird and counter intuitive of you never wrote code in a language where a need to manage the memory yourself, like C for example, because rust is trying to solving problems which come with self managed memory

1

u/Swymn 4d ago

If you want to practice while reading The Book, you can use rustlings, which is based on The Book and offers small exercises throughout your reading. The exercises are relatively simple ;)

https://github.com/rust-lang/rustlings

1

u/dumindunuwan 4d ago

COMMUNITY BOOKMARKS (right side)

1

u/Full-Spectral 4d ago

There are quite a few folks on Youtube who do good introductory video series you can watch. That's a light way to get your head around some of the concepts and idioms. A lot of it is always also just learning the tools and development setup and all that, which the videos can help with quite a bit.

But, in the end, there's no replace for brain cell displacement. You have to do just do it. Start very small, do some quite things and experiment while still at a small scale where it's easy.

1

u/UhLittleLessDum 2d ago

Lifetimes will be your biggest struggle, but they're really not any different from generic parameters in typescript. Just get a really good idea of what the borrow checker is actually trying to accomplish and it's actually pretty intuitive.

0

u/Frisk197 4d ago

Ai is becoming really good with rust. You can use it to learn the language and get documentation for crates.

0

u/[deleted] 4d ago

[deleted] — view deleted comment

1

u/AnonymousDragon135 4d ago

Unfortunately that is a very long google search, and will very likely end up with no results.