add solutions for variables

This commit is contained in:
sunface 2022-03-01 22:06:38 +08:00
parent 47d37b6940
commit 258f0ed589
32 changed files with 85 additions and 24 deletions

View File

@ -87,4 +87,6 @@ fn main() {
let unit: () = ();
assert!(size_of_val(&unit) == 4);
}
```
```
> You can find the solutions [here](https://github.com/sunface/rust-by-practice)(under the solutions path), but only use it when you need it

View File

@ -40,4 +40,6 @@ fn never_return() -> ! {
// implement this function, don't modify fn signatures
}
```
```
> You can find the solutions [here](https://github.com/sunface/rust-by-practice)(under the solutions path), but only use it when you need it

View File

@ -163,3 +163,5 @@ fn main() {
println!("0x80 >> 2 is 0x{:x}", 0x80u32 >> 2);
}
```
> You can find the solutions [here](https://github.com/sunface/rust-by-practice)(under the solutions path), but only use it when you need it

View File

@ -56,4 +56,6 @@ fn main() {}
fn sum(x: i32, y: i32) -> i32 {
x + y;
}
```
```
> You can find the solutions [here](https://github.com/sunface/rust-by-practice)(under the solutions path), but only use it when you need it

View File

@ -87,3 +87,4 @@ fn main() {
```
> You can find the solutions [here](https://github.com/sunface/rust-by-practice)(under the solutions path), but only use it when you need it

View File

@ -70,7 +70,7 @@ fn main() {
}
```
🌟🌟 使用枚举对类型进行同一化
🌟🌟
```rust,editable
@ -198,4 +198,6 @@ fn main() {
println!("linked list has length: {}", list.len());
println!("{}", list.stringify());
}
```
```
> You can find the solutions [here](https://github.com/sunface/rust-by-practice)(under the solutions path), but only use it when you need it

View File

@ -86,3 +86,5 @@ fn first_word(s: &str) -> &str {
&s[..1]
}
```
> You can find the solutions [here](https://github.com/sunface/rust-by-practice)(under the solutions path), but only use it when you need it

View File

@ -251,5 +251,4 @@ fn main() {
}
```
> You can find the solutions [here](https://github.com/sunface/rust-by-practice)(under the solutions path), but only use it when you need it

View File

@ -213,4 +213,6 @@ fn main() {
println!("{}, {}, {:?}",f.name, f.data, f);
}
```
```
> You can find the solutions [here](https://github.com/sunface/rust-by-practice)(under the solutions path), but only use it when you need it

View File

@ -75,3 +75,5 @@ fn sum_multiply(nums: (i32, i32)) -> (i32, i32) {
(nums.0 + nums.1, nums.0 * nums.1)
}
```
> You can find the solutions [here](https://github.com/sunface/rust-by-practice)(under the solutions path), but only use it when you need it

View File

@ -242,4 +242,6 @@ fn main() {
assert!(count == __)
}
```
```
> You can find the solutions [here](https://github.com/sunface/rust-by-practice)(under the solutions path), but only use it when you need it

View File

@ -163,4 +163,6 @@ fn main() {
// add one line below to make a compiler error: cannot borrow `s` as mutable more than once at a time
// you can't use r1 and r2 at the same time
}
```
```
> You can find the solutions [here](https://github.com/sunface/rust-by-practice)(under the solutions path), but only use it when you need it

View File

@ -161,3 +161,6 @@ fn main() {
println!("{:?}, {:?}, {:?}", s1, s2, t);
}
```
> You can find the solutions [here](https://github.com/sunface/rust-by-practice)(under the solutions path), but only use it when you need it

View File

@ -193,3 +193,6 @@ fn main() {
}
}
```
> You can find the solutions [here](https://github.com/sunface/rust-by-practice)(under the solutions path), but only use it when you need it

View File

@ -95,4 +95,6 @@ fn main() {
}
}
}
```
```
> You can find the solutions [here](https://github.com/sunface/rust-by-practice)(under the solutions path), but only use it when you need it

View File

@ -143,4 +143,7 @@ fn main() {
// fill the blank to make the code work
assert_eq!([x,y], __);
}
```
```
> You can find the solutions [here](https://github.com/sunface/rust-by-practice)(under the solutions path), but only use it when you need it

View File

@ -84,4 +84,6 @@ fn main() {
let unit: () = ();
assert!(size_of_val(&unit) == 4);
}
```
```
> 你可以在[这里](https://github.com/sunface/rust-by-practice)找到答案(在 solutions 路径下)

View File

@ -40,4 +40,6 @@ fn never_return() -> ! {
// 实现这个函数,不要修改函数签名!
}
```
```
> 你可以在[这里](https://github.com/sunface/rust-by-practice)找到答案(在 solutions 路径下)

View File

@ -163,3 +163,5 @@ fn main() {
println!("0x80 >> 2 is 0x{:x}", 0x80u32 >> 2);
}
```
> 你可以在[这里](https://github.com/sunface/rust-by-practice)找到答案(在 solutions 路径下)

View File

@ -56,4 +56,6 @@ fn main() {}
fn sum(x: i32, y: i32) -> i32 {
x + y;
}
```
```
> 你可以在[这里](https://github.com/sunface/rust-by-practice)找到答案(在 solutions 路径下)

View File

@ -83,3 +83,4 @@ fn main() {
}
```
> 你可以在[这里](https://github.com/sunface/rust-by-practice)找到答案(在 solutions 路径下)

View File

@ -189,4 +189,6 @@ fn main() {
println!("链表的长度是: {}", list.len());
println!("{}", list.stringify());
}
```
```
> 你可以在[这里](https://github.com/sunface/rust-by-practice)找到答案(在 solutions 路径下)

View File

@ -88,3 +88,5 @@ fn first_word(s: &str) -> &str {
&s[..1]
}
```
> 你可以在[这里](https://github.com/sunface/rust-by-practice)找到答案(在 solutions 路径下)

View File

@ -255,4 +255,4 @@ fn main() {
```
> 你可以在[这里](https://github.com/sunface/rust-by-practice)找到答案(在 solutions 路径下)

View File

@ -215,4 +215,6 @@ fn main() {
println!("{}, {}, {:?}",f.name, f.data, f);
}
```
```
> 你可以在[这里](https://github.com/sunface/rust-by-practice)找到答案(在 solutions 路径下)

View File

@ -75,3 +75,6 @@ fn sum_multiply(nums: (i32, i32)) -> (i32, i32) {
(nums.0 + nums.1, nums.0 * nums.1)
}
```
> 你可以在[这里](https://github.com/sunface/rust-by-practice)找到答案(在 solutions 路径下)

View File

@ -240,4 +240,6 @@ fn main() {
assert!(count == __)
}
```
```
> 你可以在[这里](https://github.com/sunface/rust-by-practice)找到答案(在 solutions 路径下)

View File

@ -163,4 +163,6 @@ fn main() {
// 在下面增加一行代码人为制造编译错误cannot borrow `s` as mutable more than once at a time
// 你不能同时使用 r1 和 r2
}
```
```
> 你可以在[这里](https://github.com/sunface/rust-by-practice)找到答案(在 solutions 路径下)

View File

@ -164,4 +164,6 @@ fn main() {
println!("{:?}, {:?}, {:?}", s1, s2, t);
}
```
```
> 你可以在[这里](https://github.com/sunface/rust-by-practice)找到答案(在 solutions 路径下)

View File

@ -192,4 +192,6 @@ fn main() {
_ => ()
}
}
```
```
> 你可以在[这里](https://github.com/sunface/rust-by-practice)找到答案(在 solutions 路径下)

View File

@ -95,4 +95,6 @@ fn main() {
}
}
}
```
```
> 你可以在[这里](https://github.com/sunface/rust-by-practice)找到答案(在 solutions 路径下)

View File

@ -141,4 +141,6 @@ fn main() {
// 填空,让代码工作
assert_eq!([x,y], __);
}
```
```
> 你可以在[这里](https://github.com/sunface/rust-by-practice)找到答案(在 solutions 路径下)