Rust
rust is a programming language.
Cargo
| Comments | |
|---|---|
| cargo new <project-name> --bin | |
| cargo build | |
| cargo run |
Advanced concepts
Aliasing means one memory space is referenced by multiple references.
As aliasing a mutation together is the problem, rust prevent that to happen at the same time.
Ownership
In Rust, unlike C++, by default, on a function call, the ownership of parameters is transferred; the copy should be explicit (.clone()). Therefore, parameters cannot be reused after the function call.
Borrowing
Cannot mutate while shared.
Mutable borrow
Cannot access while borrowed.
Can access the mutable borrowed variable.
Lifetime reference
Traits
Marker traits
- trait Send { }: Safe to send between thread: String, u32, Arc<String>
- trait Copy { }: Safe to memcpy: u32, f32,
References
| The Rust Programming Language | https://doc.rust-lang.org/book/ch00-00-introduction.html |
| C++Now 2017: Niko Matsakis "Rust: Hack Without Fear!" | https://www.youtube.com/watch?v=lO1z-7cuRYI |