diff --git a/contents/SUMMARY.md b/contents/SUMMARY.md index 4147c7af..68a9fd41 100644 --- a/contents/SUMMARY.md +++ b/contents/SUMMARY.md @@ -92,6 +92,7 @@ - [Unsafe Rust](advance/unsafe/intro.md) - [五种兵器](advance/unsafe/superpowers.md) + - [内联汇编 todo](advance/unsafe/inline-asm.md) - [Macro宏编程](advance/macro.md) diff --git a/contents/advance/unsafe/inline-asm.md b/contents/advance/unsafe/inline-asm.md new file mode 100644 index 00000000..b35d9615 --- /dev/null +++ b/contents/advance/unsafe/inline-asm.md @@ -0,0 +1 @@ +# 内联汇编 diff --git a/contents/basic/variable.md b/contents/basic/variable.md index 2f742f8a..ba9b70db 100644 --- a/contents/basic/variable.md +++ b/contents/basic/variable.md @@ -115,13 +115,22 @@ fn main() { ### 解构式赋值 在 [Rust 1.59](https://course.rs/appendix/rust-versions/1.59.html) 版本后,我们可以在赋值语句的左式中使用元组、切片和结构体模式了。 ```rust -let (a, b, c, d, e); +struct Struct { + e: i32 +} + +fn main() { + let (x, y) = (1.0, 2.0); + + + let (a, b, c, d, e); -(a, b) = (1, 2); -[c, .., d, _] = [1, 2, 3, 4, 5]; -Struct { e, .. } = Struct { e: 5, f: 3 }; + (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]); + assert_eq!([1, 2, 1, 4, 5], [a, b, c, d, e]); +} ``` 这种使用方式跟之前的 `let` 保持了一致性,但是 `let` 会重新绑定,而这里仅仅是对之前绑定的变量进行再赋值。