Tutorial by Examples

All values in Rust have exactly one owner. The owner is responsible for dropping that value when it goes out of scope, and is the only one who may move the ownership of the value. The owner of a value may give away references to it by letting other pieces of code borrow that value. At any given time...
All values in Rust have a lifetime. A value's lifetime spans the segment of code from the value is introduced to where it is moved, or the end of the containing scope { let x = String::from("hello"); // + // ... : let y = S...
Most of the questions around ownership come up when writing functions. When you specify the types of a function's arguments, you may choose how that value is passed in. If you only need read-only access, you can take an immutable reference: fn foo(x: &String) { // foo is only authorized to...
Some Rust types implement the Copy trait. Types that are Copy can be moved without owning the value in question. This is because the contents of the value can simply be copied byte-for-byte in memory to produce a new, identical value. Most primitives in Rust (bool, usize, f64, etc.) are Copy. let x...

Page 1 of 1