6 ms·
Rust Lang in a nutshell
- vsnf 7y agoSee also, https://doc.rust-lang.org/book/title-page.html https://doc.rust-lang.org/book/title-page.html
- rgoulter 7y agoI tend to like "Learn X in Y minutes" for a quick overview of common syntax / constructs. https://learnxinyminutes.com/docs/rust/ https://learnxinyminutes.com/docs/rust/
- psibi 7y agoI have written down the summary of the Rust book when I was learning and going through the book: https://github.com/psibi/rust-book-summary https://github.com/psibi/rust-book-summary It's much denser than "Learn X in Y minutes" but it covers more.
- savolai 7y agolet s1 ="hello world"; let s2 = s1; // copied – x1 is still valid let x1 = 2; let x2 = x1; // copied – x1 is still valid println!("{} for the {}nd time!", s1, x1); Typo in first comment? s1 vs x1?
- msrokk 7y agofixed, thank you
- Karliss 7y agoExample for skipping return keyword in case of early return is just wrong. It can be made to work if you have if x > 0 { x } else { x + 1 } but then it isn't early return anymore.
- wycy 7y agoYeah the early return example is wrong. Demonstration code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=fn%20main()%20%7B%0A%20%20%20%20println!(%22foo(3)%3D%7B%7D%22%2Cfoo(3))%3B%0A%20%20%20%20println!(%22foo(-3)%3D%7B%7D%22%2Cfoo(-3))%3B%0A%7D%0A%0Afn%20foo(x%3A%20i32)%20-%3E%20i32%20%7B%0A%20%20%20%20if%20x%20%3E%200%20%7B%0A%20%20%20%20%20%20%20%20return%20x%3B%20%0A%20%20%20%20%7D%0A%20%20%20%20x%20%2B%201%0A%7D https://play.rust-lang.org/?version=stable&mode=debug&editio... Try removing the `return` and the semicolon.
- bartkk 7y agoThank you. We fixed this unfortunate example, and added some more explanation.
- mcjiggerlog 7y agoLooks like it's down. Webcache version - https://webcache.googleusercontent.com/search?q=cache:SHrbchRsRpQJ:https://www.softax.pl/blog/rust-lang-in-a-nutshell-1-introduction https://webcache.googleusercontent.com/search?q=cache:SHrbch...
- msrokk 7y agowe had some trouble but now it’s working
- dantodor 7y agoErr Too many redirects
- msrokk 7y agowe had some trouble but now it’s working
- Lorkki 7y agoThis seems like a fairly gentle introduction. I will definitely consider it as a starting point for more junior developers interested in touching our Rust code. For those with more experience, Rust By Example walks through the same concepts in a more compact form that also lets you experiment with the code in your browser: https://doc.rust-lang.org/rust-by-example/index.html https://doc.rust-lang.org/rust-by-example/index.html
- chrismorgan 7y agoSkimming through this, there are syntax errors (e.g. → instead of -> and ’ instead of ' in some function signatures), inconsistencies in code style, and a number of content errors (e.g. the content surrounding early return is still quite wrong and suggests a lack of understanding of the actual feature, expression-orientation; and the description of what &str is; and the description of Copy and copy semantics being simplified beyond what I would consider truth). Overall it’s a decent summary and most of the content seems correct, but be careful.
- sansnomme 7y agoThe arrow thing is probably just editor font ligatures.
- deleted 7y ago[deleted]
- xwowsersx 7y agoI highly, highly recommend this crash course from Michael Snoyman: https://www.snoyman.com/blog/2018/10/introducing-rust-crash-course https://www.snoyman.com/blog/2018/10/introducing-rust-crash-...
- lordleft 7y agoI'm increasingly intrigued by Rust. Can anyone recommend a good analysis / benchmarking of Rust compared to C/C++ code? Curious how it fares on a performance basis.
- bluejekyll 7y agoThis is by no means scientific, but it’s a fun benchmark, there’s some debate about the fastest Rust options submitted (ie I believe there were faster than C versions that were rejected). C: https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/rust.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/... Clang (for common llvm backend between rust and c): https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/rust-clang.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/... C++: https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/rust-gpp.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/... Rust is pretty much on par with both C and C++.
- rumanator 7y ago> This is by no means scientific, It's actually very scientific (testing hypothesis, measuring results, etc) but might not be generalizable.
- tasubotadas 7y agoWhat's missing in these tests is that they do not capture the required knowledge by the developer to achieve those results. If anybody has actually checked C/C++ examples, one could see that they use non-trivial techniques/libraries to achieve superior performance. What would be REALLY interesting to see is breakdown of the performance by the years of experience of people that submitted working code examples. I have a feeling that a developer with one year of experience in Java, will probably beat developers with two years of experience in C/C++.
- igouy 7y agoDo you have an example of program performance measurements that do "capture the required knowledge by the developer" ? How can you tell that the knowledge was actually "required" rather than incidental ? Wouldn't it depend exactly what experience they gained in that one year and how relevant it was to the task at hand?
- brianzelip 7y agoJust heard an insightful (for an outsider) podcast episode on Rust with the folks behind much of the resources being shared here in this thread. _An Introduction to Rust featuring Carol Nichols and Jake Goulding_, https://www.heroku.com/podcasts/codeish/34-an-introduction-to-rust https://www.heroku.com/podcasts/codeish/34-an-introduction-t...
- cpascal 7y agoIf you are more of an interactive learner I would recommend installing rust on your machine and then cloning the rustlings repo https://github.com/rust-lang/rustlings https://github.com/rust-lang/rustlings. Rustlings is an interactive collection of rust exercises that are either incorrect or incomplete. The exercises are grouped into key concepts of rust and cross referenced with relevant chapters in the rust book https://doc.rust-lang.org/book/ https://doc.rust-lang.org/book/ The general flow is to open up the given chapter of the rust book for a set of exercises and hack away at them until they compile. It's a good way to quickly get an introduction to rust and its core features.
- tasubotadas 7y agoHaving gone through rustlings while learning rust, I can say that apart syntax overview, they are almost useless. I was much more successful by studying the rust book while trying to solve/implement not completely trivial pet projects.
- QueijoFresco 7y agoDo you mind sharing what kind of projects? Just in case you have a list laying around.
- tasubotadas 7y agoThat would be something like: * ToDo list with UI * Stock Quote retrieval/analysis * Toy VM/Interpreter
- hechang1997 7y ago"Too many linkedlists" is an excellent tutorial for understanding ownership IMO.