Skip to content

Commit b86458d

Browse files
committed
refactor(course/code/15): 将 std 导入本地化到各个结构体
- 移除全局作用域中的 std 模块导入 - 在 One、Two、Three 结构体内部分别添加 std 导入 - 改进代码作用域和模块化组织
1 parent 58f5379 commit b86458d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

course/code/15/hello_world.zig

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const std = @import("std");
2-
31
pub fn main() !void {
42
try One.main();
53
try Two.main();
@@ -8,6 +6,7 @@ pub fn main() !void {
86

97
const One = struct {
108
// #region one
9+
const std = @import("std");
1110
pub fn main() !void {
1211
std.debug.print("Hello, World!\n", .{});
1312
}
@@ -16,6 +15,7 @@ const One = struct {
1615

1716
const Two = struct {
1817
// #region two
18+
const std = @import("std");
1919
pub fn main() !void {
2020
var stdout_buffer: [1024]u8 = undefined;
2121
var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
@@ -35,6 +35,7 @@ const Two = struct {
3535

3636
const Three = struct {
3737
// #region three
38+
const std = @import("std");
3839
pub fn main() !void {
3940
// 定义两个缓冲区
4041
var stdout_buffer: [1024]u8 = undefined; // [!code focus]

0 commit comments

Comments
 (0)