Rust: from zero to pretty-well-versed in 30 minutes
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:
“letintroduces a variable binding […]”
then takes you through
- Modules
- Blocks
- Conditionals
- Matches
Optionsmutables- Copy/clone semantics
- Traits
- Generic parameters
- Constraints
- Macros
- Enums
- Lifetimes and borrowing
- Generic lifetimes
- Statics vs. owned vs. referenced
- Slices and range literals (
IndexandIndexMut) Results- Errors,
panicandunwrap,expect()and? - Closures (
Fn,FnMut, andFnOnce) movefor … 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