Assume I have the following structure
struct Test {
value : i32,
}
and I implement the following method for it
impl Test {
fn take_ownership(self) -> Option<Self> {
if self.value >= 0 {
Some(self)
} else {
None
}
}
}
I am good with the consumption of the ownership in the case when value
is greater than 0
, but how can I rewrite the code so that the ownership is not consumed in the case None
is returned?