Github repo: https://github.com/caveofprogramming/rust
If Let
If you just want to get one value out of an enum
, you can use the if let
statement
.The println
here only executes if value
is set to Some
, and not None
.
After if let
we write a pattern describing the thing we’re looking for. I’ve given it a variable name number
here, which we can then use if it successfully matches.
This can also be used as an expression, in which case we have to supply an else
, to cover all possibilities.
Packages and Crates
The Rust docs say a crate is a unit of code. So main.rs is a crate.
Crates can contain modules.
A crate can be a binary crate or a library crate.
Binary crates compile to programs and must have a main
.
Library crates don’t have a main and are libraries of code.
The crate root is a source file providing the starting point for the compiler, for example main.rs.
A package is a bundle of crates and contains a Cargo.toml.
A package can contain more than one binary crate but only one library crate.