I have some pseudocode that checks if a variable is null
:
Test test;
if (test == null) {
test = new Test();
}
return test;
How would I do something like this in Rust? This is my attempt so far:
struct Test {
time: f64,
test: Test,
}
impl Test {
fn get(&self) -> Test {
if self.test == null {
// <--
self.test = Test { time: 1f64 };
} else {
self.test
}
}
}