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.
1.6 KiB
1.6 KiB
question_mark
Instructions
You will have to create 3 structures:
One
, that contains one element calledfirst_layer
it should be anOption
for the structureTwo
.Two
, that contains one element calledsecond_layer
it should be anOption
for the structureThree
.Three
, that contains one element calledthird_layer
it should be anOption
for the structureFour
.Four
, that contains one element calledfourth_layer
it should be anu16
that is anOption
.
Beside the structure you must create a function named get_fourth_layer
that is associated to the One
structure.
This function should return the Option
value in the Four
structure.
Expected Function
pub struct One {
// expected public fields
}
pub struct Two {
// expected public fields
}
pub struct Three {
// expected public fields
}
pub struct Four {
// expected public fields
}
impl One {
pub fn get_fourth_layer(&self) -> Option<u16> {}
}
Usage
Here is a program to test your function
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
})
}
And its output:
student@ubuntu:~/[[ROOT]]/test$ cargo run
1000
student@ubuntu:~/[[ROOT]]/test$