Replies: 89 comments 111 replies
-
这章的爬坡陡度太高了,可能是基础知识还是没掌握 |
Beta Was this translation helpful? Give feedback.
-
后面会对生命周期两个章节进行下大幅优化,目前确实存在一些问题 |
Beta Was this translation helpful? Give feedback.
-
最后的这个例子中的错误实在是...太反直觉了。 |
Beta Was this translation helpful? Give feedback.
-
&*self 是为什么, 不能是&self呢 |
Beta Was this translation helpful? Give feedback.
-
看前:我是新手,就是想头铁 0 0 |
Beta Was this translation helpful? Give feedback.
-
建议加入Variance相关的知识点,目前的内容貌似没有cover这块难点 |
Beta Was this translation helpful? Give feedback.
-
&self &Self &*self self 啥区别啊,越看越蒙😒 |
Beta Was this translation helpful? Give feedback.
-
无语感觉自己在看天书了。。。太玄幻了 |
Beta Was this translation helpful? Give feedback.
-
写的很通俗易懂!飞哥🐂🍺 |
Beta Was this translation helpful? Give feedback.
-
大佬,针对例2的情况怎么解决那? |
Beta Was this translation helpful? Give feedback.
-
关于再借用
这是可以运行的。 我理解是: 理解的对吗? |
Beta Was this translation helpful? Give feedback.
-
rustc 1.61.0 第一个例子可以了 |
Beta Was this translation helpful? Give feedback.
-
都说学rust是陡坡,感觉形容悬崖更合适。 |
Beta Was this translation helpful? Give feedback.
-
真复杂。好难懂。 |
Beta Was this translation helpful? Give feedback.
-
我想挑战一下我的软肋 |
Beta Was this translation helpful? Give feedback.
-
个人认为,作者最后一个例子出错的原因是,返回参数Interface和输入参数&'a mut self的生命周期是一样的,list用到了最后,所以返回参数Interface也活到了最后,所以Interface一直到最后到保持了对self.manager的可变引用,所以才会说可变引用和不可变引用同时存在的作用。和作者说的“而 List 的生命周期也是 'a,说明该方法至少活得跟 List 一样久”,我感觉是没有关系的 |
Beta Was this translation helpful? Give feedback.
-
闭包函数的消除规则那的 |
Beta Was this translation helpful? Give feedback.
-
不知道对于最后一个例子的想法对不对,这里方法其实也可以看成一个引用吧(方法不就是一个指针吗,引用也是一个指针。。。。)? |
Beta Was this translation helpful? Give feedback.
-
我理解第一个例子报错的原因在于之前在2.2.3章节中说到的:引用必须总是有效的。所以在loan这个变量存在过程中,还需要使用到&mut self,最终导致了报错。哪怕方法已经调用完成,但是借用还存在,和可变借用存在关联。这也和编译器报错内容符合。编辑器在12行报不可变借用发生在这里,13行报可变借用之后在这里使用。 ============================================================================= 我写了一个简化版的,内容如下,报错和上面作者的报错基本一致。 fn main() { let loan = &mut foo; println!("{:?}",foo); println!("{:?}", loan); 如有错误希望大家可以指出,非常感谢。 |
Beta Was this translation helpful? Give feedback.
-
最后一个复杂例子相当于用新的标注 b 来标注 List,Interface 的生命周期 a 来依赖这个 b 的生命周期(利用生命周期约束来标注),达到 Interface 可以和 a 也就是List 相同的生命周期 —— 隔离了原来的,创建了新的 |
Beta Was this translation helpful? Give feedback.
-
关于闭包,强行标注生命周期也是可以通过编译的,就是费劲,还是普通函数好。 let closure_slision: &dyn for<'x> Fn(&'x i32) -> &'x i32 = &|x: &i32| -> &i32 { x }; |
Beta Was this translation helpful? Give feedback.
-
fn main() {
} fn fun<'a>(x: &'a i32) -> impl Fn(&'a i32) -> &'a i32 { fn fun2<T, F: Fn(&T) -> &T>(f: F) -> F { |
Beta Was this translation helpful? Give feedback.
-
fn main() {
let closure: &dyn Fn(&i32) -> &i32 = &|x| { x };
println!("{}", closure(&114))
} 根据编译器的提示一步步改的,没想到最后过了 |
Beta Was this translation helpful? Give feedback.
-
What I need is another C, not another C++language |
Beta Was this translation helpful? Give feedback.
-
use std::vec::Vec; |
Beta Was this translation helpful? Give feedback.
-
rust最大的难点就是生命周期设计了。哎,学习起来好吃力! |
Beta Was this translation helpful? Give feedback.
-
'a:'b,表示 'a 至少要活得跟 'b 一样久。 |
Beta Was this translation helpful? Give feedback.
-
最后一个例子可以理解为:通过新建一个生命周期,传递给借用对象,缩短再借用的时间。 |
Beta Was this translation helpful? Give feedback.
-
#[derive(Debug)]
struct Foo;
impl Foo {
fn mutate_and_share(&mut self) -> &Self {
&*self
}
fn share(&self) {}
}
fn main() {
let mut foo = Foo;
let loan = foo.mutate_and_share();
loan.share();
println!("{:?}", loan);
} |
Beta Was this translation helpful? Give feedback.
-
https://course.rs/advance/lifetime/advance.html
Beta Was this translation helpful? Give feedback.
All reactions