mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.1 KiB
48 lines
1.1 KiB
4 years ago
|
use question_mark::*;
|
||
|
|
||
|
fn main() {
|
||
|
let a = One {
|
||
|
first_layer : Some(Two {
|
||
|
second_layer: Some(Three {
|
||
|
third_layer: Some(Four {
|
||
|
fourth_layer: Some(1000)
|
||
|
})
|
||
|
})
|
||
|
})
|
||
|
};
|
||
|
|
||
|
// output: 1000
|
||
|
println!("{:?}", match a.get_fourth_layer() {
|
||
|
Some(e) => e,
|
||
|
None => 0
|
||
|
})
|
||
|
}
|
||
|
|
||
|
#[cfg(test)]
|
||
|
mod tests {
|
||
|
use super::*;
|
||
|
#[test]
|
||
|
fn test_value() {
|
||
|
let a = One {
|
||
|
first_layer : Some(Two {
|
||
|
second_layer: Some(Three {
|
||
|
third_layer: Some(Four {
|
||
|
fourth_layer: Some(1000)
|
||
|
})
|
||
|
})
|
||
|
})
|
||
|
};
|
||
|
let b = One {
|
||
|
first_layer : Some(Two {
|
||
|
second_layer: Some(Three {
|
||
|
third_layer: Some(Four {
|
||
|
fourth_layer: Some(3)
|
||
|
})
|
||
|
})
|
||
|
})
|
||
|
};
|
||
|
assert_eq!(a.get_fourth_layer(), Some(1000));
|
||
|
assert_eq!(b.get_fourth_layer(), Some(3));
|
||
|
}
|
||
|
}
|