From b739ff3a06422b016eaefe110ec6671b7d5ee3a8 Mon Sep 17 00:00:00 2001 From: jinzhongjia Date: Fri, 1 Nov 2024 14:41:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=88=86=E5=89=B2=20PR=20=E7=A4=BA?= =?UTF-8?q?=E4=BE=8B=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- course/basic/define-variable.md | 9 ++------- course/code/12/define_variable.zig | 13 +++++++++++++ course/code/14/define_variable.zig | 13 +++++++++++++ 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/course/basic/define-variable.md b/course/basic/define-variable.md index 61921e11..b395290d 100644 --- a/course/basic/define-variable.md +++ b/course/basic/define-variable.md @@ -107,11 +107,6 @@ PS:说实话,我认为这个设计并不太好。 ## 解构赋值(Destructuring Assignment) -解构赋值是 0.12 新引入的语法,允许对可索引的聚合结构(如元组、向量和数组)进行解构。 +解构赋值是 `0.12` 新引入的语法,允许对可索引的聚合结构(如元组、向量和数组)进行解构。 -```zig -var z: u32 = undefined; -const x, var y, z = [3]u32{ 1, 2, 3 }; -y += 10; -// x 是 1,y 是 2,z 是 3 -``` +<<<@/code/release/define_variable.zig#deconstruct diff --git a/course/code/12/define_variable.zig b/course/code/12/define_variable.zig index 71aebadb..a8cbe2cf 100644 --- a/course/code/12/define_variable.zig +++ b/course/code/12/define_variable.zig @@ -133,3 +133,16 @@ const Block = struct { _ = x; } }; + +const Deconstruct = struct { + fn main() void { + // #region deconstruct + var z: u32 = undefined; + // var z: u32 = undefined; + const x, var y, z = [3]u32{ 1, 2, 3 }; + y += 10; + // x 是 1,y 是 2,z 是 3 + // #endregion deconstruct + _ = x; + } +}; diff --git a/course/code/14/define_variable.zig b/course/code/14/define_variable.zig index 71aebadb..a8cbe2cf 100644 --- a/course/code/14/define_variable.zig +++ b/course/code/14/define_variable.zig @@ -133,3 +133,16 @@ const Block = struct { _ = x; } }; + +const Deconstruct = struct { + fn main() void { + // #region deconstruct + var z: u32 = undefined; + // var z: u32 = undefined; + const x, var y, z = [3]u32{ 1, 2, 3 }; + y += 10; + // x 是 1,y 是 2,z 是 3 + // #endregion deconstruct + _ = x; + } +};