Rust
Learning Resources
- The Rust Programming Language (THE Rust Reference/Learning Book) rustlang-book: https://doc.rust-lang.org/stable/book/ "The Rust Programming Language (THE Rust Reference/Learning Book)"
- Writing a NES Emulator in Rust (from bugzmanov.github.io/nes_ebook/)
- Write a NES emulator using Rust!
- Fantastic intermediate rust overview with a focus on systems programming
- Considering Rust (from YouTube by Jon Gjengset)
- Great talk by Jon Gjengset
- Gets you the basic ideas of Rust's capabilities
- rustlings: Small exercizes to get started reading & writing rust code (from GitHub by rust-lang)
- Great byte sized exercizes to learn rust
- Do these once a week or something
Collections
Hello World!
Iteration
The iter()
function generates an iterator trait to
iterate a collection of values by reference.
This includes arrays, vectors, slices, etc.
The function will return an iterator of type T
,
where T is the reference type of the elements of the collection.
Iterators have a wide array, pun intended,
of functions to help performing actions on all or specific collection items.
There's the next()
, position()
, Map
, Filter
, but most importantly
it can function inside loop structures to define the loop.
Position
The Iterator
trait comes with it the position()
function that,
with the help of a predicate expression passed into it,
find the index of an item in a collection.
Using the function signature,
Iterator.position(predicate: P) -> Option<usize>
,
you simply pass a predicate expression into it and get the index or None in return.
names = ["Bob", "Steve", "Karen", "Lindsey"];
index = names.iter().position(|&n: String| n == "Karen").unrwap();
println!("{} has index of {}", names[index], index)
The above code snippet sets up a vector of name strings.
An index
is set from calling position
with predicate
n == "Karen"
from lambda function of arg |&n: String|
.
Then the index
is found,
since it's found and unwrap
ed it can access the name Karen
.
Optionals
References
Note References
Web References
- The Rust Programming Language (THE Rust Reference/Learning Book)
- Writing a NES Emulator in Rust (from bugzmanov.github.io/nes_ebook/)
- Considering Rust (from YouTube by Jon Gjengset)
- rustlings: Small exercizes to get started reading & writing rust code (from GitHub by rust-lang)
- Rust Documentation: Module std::collections