# Verify installation
rustc --version
cargo --version
# Run
cargo run --bin hello
# Cloning this repo
git clone [email protected]:t4sk/hello-rust.git
cd hello-rust
cargo build
- Install cargo
- Hello world
-
println!
- Variable
- Immutable by default
let
mut
- Constant
- Shadowing
- Type placeholder
_
- Scalar types
i32
,u32
,f32
,bool
,char
- Type conversion
- Min and max value
- Integer overflow
- Compound data types
- String
r#
usize
format!
- Enum
Option
Result
derive(Debug, PartialEq)
- Struct
- Update syntax
- Struct method (
impl
)Self
,self
- Associated function (static method)
- Methods (functions called on a particular instance of type)
- Operators
- Math
- Bool
- Comparison
- Bitwise
- if / else
- loop
- for and range
- while
- returning values from loop
usize
- label
- match
- match on
Option
andResult
_
to match rest@
- match on
- if let and let else
- function
- no return value
- return value
- implicit return
- mod
- visibility,
pub
use
,super
- nested
- struct
-
crate
- visibility,
- error handling
- panic
- option
- result
- expect, unwrap
-
?
-
Box<dyn Error>
- ownership
- stack and heap
- stack (last in, first out)
- store data with known fixed size
- heap
- vec (stack = vec pointer, data = heap)
- stack (last in, first out)
- Each value in Rust has an owner.
- There can only be one owner at a time. (Transfer of ownership for variable assignment)
- When the owner goes out of scope, the value will be dropped.
- stack and heap
- borrow
- immutable reference
- mutable reference
- cannot return ref
- function
- slice
- slice is a reference to an collection so it's always borrowed
-
String
andstr
- dereference
- trait
- basic
trait
,impl
, default impl
- common traits
- trait fn input and output
- super trait
+
- fully qualified trait
- basic
- generic types
- basic
- struct,
Option
,Result
, vector,_
- Monomorphization
- default G<T = A>
- function
- struct,
- method for generic typed struct
- generic traits
-
From
andInto
- trait bound,
+
,where
-
Sized
and?Sized
- dynamic dispatch
- dynamic dispatch,
dyn
,Box<dyn T>
- trait object
Box<dyn Error>
- dynamic dispatch,
- associated types
- basic
- operator overloading
- iterator
- vec, array, hashmap
- counter
iter
andinto_iter
,iter_mut
- iterator adaptors
map
,filter
,collect
,fold
,enumerate
,rev
,zip
- while let
- lifetimes
- elision
- static
'_
- basic
- closures
- basic
-
move
-
Fn
,FnMut
,FnOnce
- using closure as input and output
- function pointer
- difference between func pointer and fn traits and closure