-
Notifications
You must be signed in to change notification settings - Fork 7
/
example1.zig
31 lines (24 loc) · 819 Bytes
/
example1.zig
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
31
const std = @import("std");
const toml = @import("zig-toml");
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
const Address = struct {
port: i64,
host: []const u8,
};
const Config = struct {
master: bool,
expires_at: toml.DateTime,
description: []const u8,
local: *Address,
peers: []const Address,
};
pub fn main() anyerror!void {
var parser = toml.Parser(Config).init(allocator);
defer parser.deinit();
var result = try parser.parseFile("./examples/example1.toml");
defer result.deinit();
const config = result.value;
std.debug.print("{s}\nlocal address: {s}:{}\n", .{ config.description, config.local.host, config.local.port });
std.debug.print("peer0: {s}:{}\n", .{ config.peers[0].host, config.peers[0].port });
}