summaryrefslogtreecommitdiff
path: root/exercises/026_hello2.zig
diff options
context:
space:
mode:
authorChris Boesch <chrboesch@noreply.codeberg.org>2025-12-29 12:46:28 +0100
committerChris Boesch <chrboesch@noreply.codeberg.org>2025-12-29 12:46:28 +0100
commit4927ef6a2624430d9be54d40350b1c0e60a3fb06 (patch)
tree85f54e6b6f190250322c233fa5b3a9e8965b9332 /exercises/026_hello2.zig
parenta5febf58c9f9229bdf9e57df727fa45ea47d2fd6 (diff)
parente8f81ddb96208bd363df2e4cc1af906fa84f0aef (diff)
Merge pull request 'Integrate file system I/O with the std.Io interface' (#339) from std_Io into main
Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/339
Diffstat (limited to 'exercises/026_hello2.zig')
-rw-r--r--exercises/026_hello2.zig11
1 files changed, 8 insertions, 3 deletions
diff --git a/exercises/026_hello2.zig b/exercises/026_hello2.zig
index 582dba9..7daa9e2 100644
--- a/exercises/026_hello2.zig
+++ b/exercises/026_hello2.zig
@@ -5,6 +5,9 @@
//
const std = @import("std");
+// Instance for input/output operations, we'll learn how to create them later.
+const io = std.Options.debug_io;
+
// Take note that this main() definition now returns "!void" rather
// than just "void". Since there's no specific error type, this means
// that Zig will infer the error type. This is appropriate in the case
@@ -15,13 +18,15 @@ const std = @import("std");
// https://ziglang.org/documentation/master/#Inferred-Error-Sets
//
pub fn main() !void {
- // We get a Writer for Standard Out so we can print() to it.
- var stdout = std.fs.File.stdout().writer(&.{});
+ // We get a Writer for Standard Out...
+ var stdout_writer = std.Io.File.stdout().writer(io, &.{});
+ // ...and extract its interface so we can print() to it.
+ const stdout = &stdout_writer.interface;
// Unlike std.debug.print(), the Standard Out writer can fail
// with an error. We don't care _what_ the error is, we want
// to be able to pass it up as a return value of main().
//
// We just learned of a single statement which can accomplish this.
- stdout.interface.print("Hello world!\n", .{});
+ stdout.print("Hello world!\n", .{});
}