ownership/ownership #211
Replies: 70 comments 30 replies
-
第3题中的 |
Beta Was this translation helpful? Give feedback.
-
第7题中,引入了 |
Beta Was this translation helpful? Give feedback.
-
第9题是不是用 |
Beta Was this translation helpful? Give feedback.
-
into_bytes 和 as_bytes 理解不了呢 |
Beta Was this translation helpful? Give feedback.
-
我在思考一个问题,就从做这些题目的角度来说 |
Beta Was this translation helpful? Give feedback.
-
done!不过第5题和第7题感觉超纲了啊!第五题还好点,就算对Copy理解的不透彻也能做,但是第7题明明还没有学习Box和Box的使用方法啊 |
Beta Was this translation helpful? Give feedback.
-
感觉有些题目的题意不太清楚,例如第 8 题我做的时候以为是只修改 |
Beta Was this translation helpful? Give feedback.
-
第1题还有一种不会报错的 fn main() {
let x = String::from("hello, world");
let y = &x;
println!("{},{}", x, y);
println!("{}", y);
} 说明println!里面发生了字符串copy,没有移走所有权 fn main() {
let x = String::from("hello, world");
let y = &x;
take_ownership(x);
println!("{}", y);
}
fn take_ownership(x: String) -> () {} |
Beta Was this translation helpful? Give feedback.
-
第九题: fn main() {
let t = (String::from("hello"), String::from("world"));
// 填空,不要修改其它代码
let (s1, s2) = (&(t.0), &(t.1));
println!("{:?}, {:?}, {:?}", s1, s2, t); // -> "hello", "world", ("hello", "world")
} |
Beta Was this translation helpful? Give feedback.
-
donedonedonedonedonedone |
Beta Was this translation helpful? Give feedback.
-
最后一题这样写不是性能更好:fn main() {
} |
Beta Was this translation helpful? Give feedback.
-
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH |
Beta Was this translation helpful? Give feedback.
-
半夜脑子不是很清醒 // 不要使用 clone,使用 copy 的方式替代
println!("{:?}, {:?}", y, y); |
Beta Was this translation helpful? Give feedback.
-
第9题我直接解构引用,就不会有所有权变更了 |
Beta Was this translation helpful? Give feedback.
-
第七题有点迷糊,回头再看 |
Beta Was this translation helpful? Give feedback.
-
fn main() {
} 感觉第七题应该是想考解引用。应该是这么写的。 |
Beta Was this translation helpful? Give feedback.
-
// 不要修改 main 中的代码
} // 只能修改下面的代码! take_ownership里面是对s1进行拷贝,还是所有权转移 |
Beta Was this translation helpful? Give feedback.
-
第9题是不是可以有3种解法:
前两种方法中,s1 和 s2 的类型是 &str(所以这两种方法是完全等价的吗?)。第三种方法中,s1 和 s2 的类型是 String。 |
Beta Was this translation helpful? Give feedback.
-
ownership/ownership
Learning Rust By Practice, narrowing the gap between beginner and skilled-dev with challenging examples, exercises and projects.
https://zh.practice.rs/ownership/ownership.html
Beta Was this translation helpful? Give feedback.
All reactions