compiler/fight-with-compiler/lifetime/too-long2 #885
Replies: 5 comments 7 replies
-
我这里编译不过, indent 里 self.target 引用那里报错了
|
Beta Was this translation helpful? Give feedback.
-
look! 加个引用的string的生命周期大于自身引用的约束,OK不OK? fn indent<'b>(&'b mut self) -> &'b mut Self where 'a: 'b {
self.indent += 1;
self
} |
Beta Was this translation helpful? Give feedback.
-
最终代码中把 fn indent(&mut self) -> Writer {
Self {
target: self.target,
indent: self.indent + 1,
}
} |
Beta Was this translation helpful? Give feedback.
-
fn indent<'b>(&'b mut self) -> Writer<'b> { |
Beta Was this translation helpful? Give feedback.
-
本质上是Self 可能会携带生命周期,在工程上还是尽量控制使用Self |
Beta Was this translation helpful? Give feedback.
-
compiler/fight-with-compiler/lifetime/too-long2
https://course.rs/compiler/fight-with-compiler/lifetime/too-long2.html
Beta Was this translation helpful? Give feedback.
All reactions