根据我的理解,Next需要&mut Test
分,但create_test()
返回Test
分.
为什么可以汇编这些内容呢?
我的猜测是,.
会隐含地将Test
转换为&mut Test
,我不确定.有谁能解释一下这件事吗?
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
}