Replies: 64 comments 88 replies
-
这里容易误导新人,一开始是变量不可变避免运行时检查从而提高性能,,后面又说不可变丧失性能,这里其实是矛盾的,没有说清楚 |
Beta Was this translation helpful? Give feedback.
-
确实,这里没有讲清楚,感谢建议 :) |
Beta Was this translation helpful? Give feedback.
-
字符串类型的这一小节,建议替换一下 fn main () { |
Beta Was this translation helpful? Give feedback.
-
好家伙,解构式赋值那块的 |
Beta Was this translation helpful? Give feedback.
-
Struct { e, .. } = Struct { e: 5 };这个绑定怎么理解呢? |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
不可变可以带来安全性,但是丧失了灵活性和性能。 如果上面这段话表达没有问题,能否详细展开说明:
|
Beta Was this translation helpful? Give feedback.
-
fn main() {
} struct Struct { 结构体解构赋值怎么忽略字段呢? |
Beta Was this translation helpful? Give feedback.
-
变量和常量还有一个区别,变量在栈stack上动态分配,而常量分配在.data静态数据段上,常量会一次性静态加载,使用时直接寻址,性能会更好。 |
Beta Was this translation helpful? Give feedback.
-
我的理解,这里let和let mut的关系,就相当于其他语言的var和const关系,是常见的特性,不知道对吗 |
Beta Was this translation helpful? Give feedback.
-
作为一个 ts 程序员,平时写代码,变量大部分都是 const 来定义,只有在真的需要重新赋值的地方才用 let,我觉得这和 let 与 let mut 差不多的思路。 |
Beta Was this translation helpful? Give feedback.
-
课后练习精心设计,很棒~ |
Beta Was this translation helpful? Give feedback.
-
为什么我照例子写的,执行cargo run,非但没报错,还正确打印出来了, |
Beta Was this translation helpful? Give feedback.
-
struct Struct {
e: i32
}
fn main() {
let (a, b, c, d, e);
(a, b) = (1, 2);
// _ 代表匹配一个值,但是我们不关心具体的值是什么,因此没有使用一个变量名而是使用了 _
[c, .., d, _] = [1, 2, 3, 4, 5];
Struct { e, .. } = Struct { e: 5 };
assert_eq!([1, 2, 1, 4, 5], [a, b, c, d, e]);
} 我不理解这个解构式赋值,请问何为“解构”呢,在赋值语句哪里中括号“[]”和小括号“()”有什么区别吗,“...”又是做什么用的呢 , 下划线"_"说是匹配一个值,在上面的例子代码中匹配的是 e 吗? |
Beta Was this translation helpful? Give feedback.
-
第一天打卡!看我可以坚持几天! |
Beta Was this translation helpful? Give feedback.
-
@isunface 能不能跟你邮件联系呀,有些问题 |
Beta Was this translation helpful? Give feedback.
-
Struct {e} = Struct {e:5}; |
Beta Was this translation helpful? Give feedback.
-
fn main() {
let (a, b, c, d, e);
(a, b) = (1, 2); // 对这里有些不理解,上面是不可变声明,为什么可以再赋值。
// ... 下面同理
} 能否理解成(我就说 let 声明不掺入 mut )
let a = 1;
a = 2 // error
let (b);
b = 2 // success |
Beta Was this translation helpful? Give feedback.
-
Rust学习第3天,心情很平静…… |
Beta Was this translation helpful? Give feedback.
-
Rust 光是在变量这一块,设计的就比较复杂啊,变量绑定,变量解构,变量遮蔽, 可变变量, 不可变常量。。。。。。东西太多了 |
Beta Was this translation helpful? Give feedback.
-
变量遮蔽(shadowing) 处建议画个两种方式执行后内存数据示意图 |
Beta Was this translation helpful? Give feedback.
-
可变的直接用var多好,还要多写一个mut😅 |
Beta Was this translation helpful? Give feedback.
-
不加mut都是不可变,那么为什么要多一个常量关键字? |
Beta Was this translation helpful? Give feedback.
-
防止多想名字,那应该设置mut,而不是不可变一直赋值 |
Beta Was this translation helpful? Give feedback.
-
data races 数据冲突也不错,抽象底层读写数据的时候,避免又读又写,机组。 |
Beta Was this translation helpful? Give feedback.
-
看了一下对应的汇编代码,总结如下:
|
Beta Was this translation helpful? Give feedback.
-
对应的习题可能超前了。这一节没有 String 类型,只有 &str // 修复错误
fn main() {
println!("{}, world", x);
}
fn define_x() {
let x = "hello";
} |
Beta Was this translation helpful? Give feedback.
-
我用rust开发了一个java虚拟机demo |
Beta Was this translation helpful? Give feedback.
-
https://course.rs/basic/variable.html
Beta Was this translation helpful? Give feedback.
All reactions