Replies: 120 comments 69 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.
-
引用上的生命周期标注是对引用指向的内存数据的作用域要求, 而不是对引用变量本身的要求 fn test<'a>(s1: &'a str, s2: &'a str) -> &'a str {
if s1.len() >= s2.len() {
s1
} else {
s2
}
}
fn main() {
let str1 = "abc".to_string();
let str2 = "cde".to_string();
let s3;
{
let s1 = &str1; // s1和s2的生命周期小于s3, 但是它们指向的数据生命周期大于s3
{
let s2 = &str2;
s3 = test(s1, s2); // OK
}
}
println!("{s3}");
} |
Beta Was this translation helpful? Give feedback.
-
大佬牛逼,就你的书看得懂到底写的是个啥了 |
Beta Was this translation helpful? Give feedback.
-
有一点很容易推理出来:由于 &'a self 是被引用的一方,因此引用它的 &'b str 必须要活得比它短,否则会出现悬垂引用。因此说明生命周期 'b 必须要比 'a 小 这句话谁来解释下,被引用和引用是怎么得出的? |
Beta Was this translation helpful? Give feedback.
-
因为编译器需要知道这些,来确保函数调用后的引用生命周期分析 |
Beta Was this translation helpful? Give feedback.
-
'static 好用,就会被滥用🐶 |
Beta Was this translation helpful? Give feedback.
-
为啥这一段可以运行? |
Beta Was this translation helpful? Give feedback.
-
看到这里感觉Rust为了应对自动垃圾回收和人工的内存管理,设置了一堆语言特性搞成一个Rust,感觉还不如C++直接释放好呢,语言特性太多了 |
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.
-
对作者函数参数生命周期的描述,我始终不好理解:
我的疑问是怎么能要求函数内的局部变量 fn useless<'a>(first: &'a i32, second: &'a i32) {
let tmp = 1;
first = &tmp; // 如没有这代码,first的被引用对象的生命周期至少和 'a 一样长,接下改变了
} 他会报如下错误:
至于 |
Beta Was this translation helpful? Give feedback.
-
666,写的真好 |
Beta Was this translation helpful? Give feedback.
-
写的很细。 |
Beta Was this translation helpful? Give feedback.
-
https://course.rs/advance/lifetime/basic.html
Beta Was this translation helpful? Give feedback.
All reactions