ownership/ownership #211
Replies: 56 comments 25 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.
-
done. ownership is so niceeeeeeeeeeeeeeeeeeeeeeeeeeee |
Beta Was this translation helpful? Give feedback.
-
第9题这样也可以: |
Beta Was this translation helpful? Give feedback.
-
做第九题的时候发现了一个疑问,这样去访问t.1的时候 是不是造成了t.1的所有权转移,导致后面去print的时候出现了问题。 但是所有权转移是在什么过程发生的,又转移到了哪里呢? 有点费解 fn main() {
} 编译器提示 |
Beta Was this translation helpful? Give feedback.
-
done batman |
Beta Was this translation helpful? Give feedback.
-
checked! |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
I did this :) (as extra playing with code) fn main() {
} |
Beta Was this translation helpful? Give feedback.
-
mark finished |
Beta Was this translation helpful? Give feedback.
-
最后一题这样写不是性能更好:fn main() {
} |
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