Published by marco on
I found the article A half-hour to learn Rust by Amos to be extremely helpful in learning the syntax and mechanics of Rust.
It starts out with the absolute basics:
“let
introduces a variable binding […]”
then takes you through
Options
mut
ablesIndex
and IndexMut
)Results
panic
and unwrap
, expect()
and ?
Fn
, FnMut
, and FnOnce
)move
for … in
and ends up with a function builder that tests strings:
fn make_tester<'a>(answer: &'a str) -> impl Fn(&str) -> bool + 'a {
move |challenge| {
challenge == answer
}
}
fn main() {
let test = make_tester("hunter2");
println!("{}", test("*******"));
println!("{}", test("hunter2"));
}
// output:
// false
// true