26. Collecting into Option
Rust’s option implements FromIterator too!
Use it when you want to get None if there is a None element and values otherwise.
| |
or values …
| |
Rust’s option implements FromIterator too!
Use it when you want to get None if there is a None element and values otherwise.
| |
or values …
| |
Rust’s option implements an iterator!
| |
Why is this useful? see example.
| |
As of 1.66, it is possible to use ..=X in patterns
| |
Instead of manually implementing Default trait for an enum, you can derive it and explicitly tell which variant should be the default one.
| |
Use Debug trait to print enum values if needed.
| |
Sometimes there is a need to zip two iterables of various lengths.
If it is known which one is longer, then use the following approach:
First one must be longer.
| |
As of 1.65, it is possible to use let statement with a refutable pattern.
| |
As of 1.65, it is possible to label plain block expression and terminate that block early.
| |
Use flatten to iterate over only Some values if you have a collection of Options.
| |
Try to avoid matching Option or Result.
Use if let instead.
| |