let 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);
Example 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.
This 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
Skimming 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.
I'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.
This 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).
One is multicore, but the other 7 winning have the same parallelism.
As for that one winning by parallelism - maybe it was just easier to provide a correct parallel solution in Rust than in C++? This game didn't appear there yesterday and C++ developers had much more time to play it. If that's the case, that benchmark still counts.
You can expect it to be in the same ballpark as C or C++ for single-threaded code, especially if you use idiomatic Rust (combinators instead of manual iteration).
Where Rust shines is that it often takes jaut a few minutes to turn a single-threaded program into a multithreaded program — and the type system guarantees that the program won't have data races.
If 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.
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/
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.
35 comments
[ 2.9 ms ] story [ 83.0 ms ] threadIt's much denser than "Learn X in Y minutes" but it covers more.
Try removing the `return` and the semicolon.
Webcache version - https://webcache.googleusercontent.com/search?q=cache:SHrbch...
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
C: https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
Clang (for common llvm backend between rust and c): https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
C++: https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
Rust is pretty much on par with both C and C++.
It's actually very scientific (testing hypothesis, measuring results, etc) but might not be generalizable.
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++.
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?
Believe but do not know? Shade?
Rust has more potential for better optimisation than C++ because the compiler has full information on pointer aliasing.
One of those C++ comparisons is currently multi-core vs sequential.
Several C++ programs were recently removed, which upends things. You might say — "there were faster than [Rust] versions that were rejected".
(The changes were in the last month or two.)
Where Rust shines is that it often takes jaut a few minutes to turn a single-threaded program into a multithreaded program — and the type system guarantees that the program won't have data races.
I wrote an overview of Rust's performance characteristics: https://kornel.ski/rust-c-speed
_An Introduction to Rust featuring Carol Nichols and Jake Goulding_, https://www.heroku.com/podcasts/codeish/34-an-introduction-t...
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/
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.
I was much more successful by studying the rust book while trying to solve/implement not completely trivial pet projects.
* ToDo list with UI
* Stock Quote retrieval/analysis
* Toy VM/Interpreter