As of 2023, 90+% of the stuff on this cheat-sheet you can figure out a lot faster by asking an AI, like ChatGPT. Ask it simply:
"Please help me write a Rust function that takes a Vector of floating point numbers and returns an array of strings"
The LLM will spit out example code in two seconds, and then within three clicks you can copy/paste that code into playground.rust-lang.org , hold down Control-Enter, and run it, and if there is an error, just copy/paste the entire error message back into ChatGPT and it will tell you what the error was and how to fix it. You can easily adapt this to your own needs much faster than building up some example from a cheatsheet.
Now if you want to learn more about something, its really easy to just ask the LLM
"Could you please explain to me how Vectors and Strings in Rust work? What are they? Explain it to
me like im 10 years old, then again like I'm an undergrad with a background in C++"
and it will just write several pages of explanation and simple examples just for you. This kind of "Cheat Sheet" is kind of becoming obsolete in the face of such technology.
This cheat sheet is in a reasonably useful state for basic things, but it does contain many errors and typos and pedagological mistakes of omission and ordering & etc.
Also note that Rust is still changing quite a bit in 2019-2022 so some of the below may be outdated/deprecated.
- Syntax tokens somewhat similar to C / C++ / Go
- Ownership of memory enforced at build time
- Statically linked
- Not so Object-Orientish, tends to be Functional-ish
- Control flow using pattern matching, Option+Result enums
- Packages: 'cargo add' command, https://crates.io
- Testing: 'cargo test' command, #[test] unit tests, integration tests
- Concurrency: ownership, mutability, channels, mutex, crossbeam + Rayon packages
- Auto formatter: 'rustfmt filename.rs' (see rust-lang.org for installation)
- compiler engine: LLVM, no non-LLVM compilers yet
- To use raw pointers, low level, call C/C++: unsafe{} keyword + ffi package
- smart pointers and reference counted: Box, Rc, Arc
- online playgrounds: https://play.rust-lang.org, https://tio.run/
- A survivial horror game where griefing is ... oops wrong Rust
- Polymorphism: Traits, Trait Extensions, Trait Objects
- Generic programming (a la C++ Templates): Generic Types
See https://www.rust-lang.org for installation details.
fn main() {
println!("Hello World");
}
$ rustc main.rs
$ ./main
Hello World