rust/tests/ui/closures/2229_closure_analysis/capture-enum-field.rs
2023-01-11 09:32:08 +00:00

28 lines
531 B
Rust

// edition:2021
// run-pass
#[derive(Debug, PartialEq, Eq)]
pub enum Color {
RGB(u8, u8, u8),
}
fn main() {
let mut color = Color::RGB(0, 0, 0);
let mut red = |v| {
let Color::RGB(ref mut r, _, _) = color;
*r = v;
};
let mut green = |v| {
let Color::RGB(_, ref mut g, _) = color;
*g = v;
};
let mut blue = |v| {
let Color::RGB(_, _, ref mut b) = color;
*b = v;
};
red(1);
green(2);
blue(3);
assert_eq!(Color::RGB(1, 2, 3), color);
}