Rust
Vectors
Initialize a vector
let vec = Vec::new();
or
let vec = vec![1,2,3]
// Initiaze repeating values (such as 5 repeat zeroes)
let vec = vec![0; 5]
Add a value to a vector
vec.push(3)
Loops
Iterators
for text in v {
}
Over a range
for n in 1..101 {
}
or
for name in names.iter() {
}
Error Handling
.unwrap()
Unwrap is best used when you are sure that you will not have an error from an Option<T>
result. The Option type will return either Some<T>
or None
. This can be useful if None
is expected, because it can then be handled appropriately.