Vector Creation and isertion // create vector let v: Vec<i32> = Vec::new(); let v = vec![1, 2, 3]; // insert elements v.push(5); When a Vector goes out of scope all its elements are freed.
Read elements To read an element we have two options:
let third: &i32 = &v[2]; v.get(2) // returns Option If we try to access an out of bound elment in the first case the program panics. Therefore the second is better for these cases....
Errors are managed by the type:
enum Result<T, E> { Ok(T), Err(E), } We can use the operator match to manage them or other ways explained below.
Unrecoverable Errors panic!("crash and burn"); Ex. access an out of bound index in an array.
Fast retrive of value To retrive value from a Result we can use the following methods:
.unwrap() .expected("error message") if Result contains an Err the program panics
Propagation To propagate an error you can either return an Err or use the ?...