-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathexample1.zig
More file actions
30 lines (24 loc) · 799 Bytes
/
example1.zig
File metadata and controls
30 lines (24 loc) · 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const std = @import("std");
const toml = @import("toml");
const Address = struct {
port: i64,
host: []const u8,
};
const Config = struct {
master: bool,
expires_at: toml.DateTime,
description: ?[]const u8 = null,
local: *Address,
peers: []const Address,
};
pub fn main(init: std.process.Init) anyerror!void {
var parser = toml.Parser(Config).init(init.gpa);
defer parser.deinit();
var result = try parser.parseFile(init.io, "./examples/example1.toml");
defer result.deinit();
const config = result.value;
if (config.description) |desc| {
std.debug.print("{s}\nlocal address: {s}:{}\n", .{ desc, config.local.host, config.local.port });
}
std.debug.print("peer0: {s}:{}\n", .{ config.peers[0].host, config.peers[0].port });
}