Merge pull request #271 from narakai/master

修正切片练习题2错误
This commit is contained in:
Sunface
2022-07-20 09:17:44 +08:00
committed by GitHub
3 changed files with 7 additions and 7 deletions

View File

@ -25,9 +25,9 @@ fn main() {
let slice = &arr[..2]; let slice = &arr[..2];
// Modify '6' to make it work // Modify '8' to make it work
// TIPS: slice( reference ) IS NOT an array, if it is an array, then `assert!` will passed: Each of the two UTF-8 chars '中' and '国' occupies 3 bytes, 2 * 3 = 6 // TIPS: slice( reference ) IS NOT an array, if it is an array, then `assert!` will passed: Each of the two chars '中' and '国' occupies 4 bytes, 2 * 4 = 8
assert!(std::mem::size_of_val(&slice) == 6); assert!(std::mem::size_of_val(&slice) == 8);
println!("Success!"); println!("Success!");
} }

View File

@ -25,9 +25,9 @@ fn main() {
let slice = &arr[..2]; let slice = &arr[..2];
// 修改数字 `6` 让代码工作 // 修改数字 `8` 让代码工作
// 小提示: 切片和数组不一样,它是引用。如果是数组的话,那下面的 `assert!` 将会通过: 因为'中'和'国'是 UTF-8 字符,它们每个占用 3 个字节,2 个字符就是 6 个字节 // 小提示: 切片和数组不一样,它是引用。如果是数组的话,那下面的 `assert!` 将会通过: '中'和'国'是char类型char类型是Unicode编码大小固定为4字节,个字符为8字节
assert!(std::mem::size_of_val(&slice) == 6); assert!(std::mem::size_of_val(&slice) == 8);
} }
``` ```

View File

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