According to my understanding, next needs a &mut Test, but create_test() returns a Test.
Why can this be compiled?
My guess is that . will implicitly convert Test to &mut Test, I am not sure. Can somebody explain more about this?
pub struct Test {
t: u64,
}
fn create_test() -> Test {
Test {
t: 1
}
}
impl Test {
pub fn next(&mut self) {
self.t = 10;
}
}
fn main() {
let mut t = Test { t: 20 };
t.next();
create_test().next(); // here
}