Open
Description
It might be worth adding a couple of bonus slides into Compound Types on irrefutable patterns, and how they can be used with let
and also as function parameters.
pub struct Weight(f32);
pub fn process_weight(Weight(kg): Weight) {
println!("Weight is {kg:.03}");
}
pub fn process_weight2(w: Weight) {
let Weight(kg) = w;
println!("Weight is {kg:.03}");
}
pub fn make_pair() -> (Weight, Weight) {
(Weight(1.0), Weight(2.0))
}
fn main() {
let (x, y) = make_pair();
process_weight(x);
process_weight2(y);
}
Metadata
Metadata
Assignees
Labels
No labels