Replies: 135 comments 78 replies
-
谢谢大佬,这本书真的写的很好😉 |
Beta Was this translation helpful? Give feedback.
-
感谢鼓励 :) |
Beta Was this translation helpful? Give feedback.
-
感谢大佬 收获好大 弄明白了很多以前糊里糊涂的概念 |
Beta Was this translation helpful? Give feedback.
-
感谢大佬,写的通俗易懂,比什么心智模型balabala一堆术语好太多了。 |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
我在想结构体上的生命周期为什么不能省略,在例子中结构体只有一个引用的时候,这个引用的有效性其实编译器是可以推断出来的啊 |
Beta Was this translation helpful? Give feedback.
-
大佬,能不能写些实际的例子?比如 teacher {vector<student&>} 另外所有的方法和结构体的生命周期均要求teacher大于student |
Beta Was this translation helpful? Give feedback.
-
“借用检查”上面那段,写成“垂悬”了 |
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.
-
首先感谢下作者,一直看这本书学习,第一次发评论。
以下代码可运行。 fn main() { 以下代码也可运行: fn main() { |
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.
-
谢谢大佬 学习了 |
Beta Was this translation helpful? Give feedback.
-
longest函数编译器完全可以做出判断返回值的生命周期,为什么不自动加上非要人去写 |
Beta Was this translation helpful? Give feedback.
-
感觉这个例子可能更好 impl<'a> ImportantExcerpt<'a> {
fn announce_and_return_part<'b, 'c>(&'a self, announcement: &'c str) -> &'b str
where
'a: 'b,
{
println!("Attention please: {announcement}");
self.part
}
} 从返回值来看,这个函数的返回值的生命周期应该由 let i = ImportantExcerpt { part: "part" };
let s;
{
let novel = "Hello, What's your name?".to_string();
s = i.announce_and_return_part(&novel);
};
println!("{:?}", s); 编译器当然要报错,毕竟 |
Beta Was this translation helpful? Give feedback.
-
'''struct ImportantExcerpt<'a> { |
Beta Was this translation helpful? Give feedback.
-
静态生命周期举一个这样的例子,感觉会更加生动: fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
if x.len() > y.len() {
x
} else {
y
}
}
fn main() {
let str1 = String::from("abcd");
let result;
{
let str2 = String::from("xyz");
result = longest(&str1, &str2);
}
// 编译错误,result可能会引用销毁的变量str2
println!("The longest string is {}", result);
} 但将变量str2的类型改成 fn main() {
let str1 = String::from("a");
let result;
{
let str2 = "xyz"; // 关键改动
result = longest(&str1, &str2);
}
println!("The longest string is {}", result);
} 这是因为str2是 |
Beta Was this translation helpful? Give feedback.
-
理解生命周期的基础概念:
|
Beta Was this translation helpful? Give feedback.
-
生命周期的标注像极了iOS的约束布局。 |
Beta Was this translation helpful? Give feedback.
-
个人认为函数的生命周期标注,是为了解决Rust的所有权特性引发的问题。 |
Beta Was this translation helpful? Give feedback.
-
不做完不爽夫斯~~终于看完这节了 休息休息 |
Beta Was this translation helpful? Give feedback.
-
太强了,看AI,看官方文档看了两天也没整明白,大佬写的一下子就看明白了,幸好是在你写了圣经之后开始学的Rust |
Beta Was this translation helpful? Give feedback.
-
rust使用生命周期标注来防止引用失效。—— Mr.Krabs |
Beta Was this translation helpful? Give feedback.
-
https://course.rs/advance/lifetime/basic.html
Beta Was this translation helpful? Give feedback.
All reactions