Пример кода:
https://play.rust-lang.org/?version=stable&mode=de...struct Child {
v: Option<i32>,
}
impl Child {
fn get_value(&self) -> Result<i32, &str> {
match self.v {
Some(v) => Ok(v),
None => Err("Values is undefined")
}
}
}
struct Parent {
child: Option<Child>,
}
impl Parent {
fn get_child_value(&self) -> Result<i32, &str> {
return match self.child {
Some(child) => child.get_value(),
None => Err("Child is undefined")
}
}
}
fn main() {
let ch = Child{v: Some(2)};
let parent = Parent{child: Some(ch)};
parent.get_child_value();
}