Conditional structures: Difference between revisions

m
→‎Match statement: fix small errors
m (→‎Match statement: fix small errors)
Line 4,691:
Some(Point { x: 0, y: 0 }) => println!("Point is on origin"),
Some(Point { x: 0, y: _ }) | Some(Point { x: _, y: 0 }) => println!("Point is on an axis"),
Some(Point {x: a, y: b}) if a == b => println!("x and y are the same value"),
Some(Point {x: ref mut a, y: ref b}) if x*a > 4 && y*b < 2 => println!("we got a mutable reference to x-value and an immutable reference to y-value."),
op @ Some(p) => println!("op is the Option<Point> while p is the contained Point"),
None => println!("We didn't get a point"),
}
}</lang>
 
====Generics (dynamic dispatch)====
Generics may also be accomplished via dynamic dispatch, so the actual code that is run is determined at compile time.