Hi,
Not sure if I just wasn't thorough enough in searching, but I have not been able to find any documentation on the std module. I'm trying to learn Zig by writing some advent of code programs, and I am specifically interested in how to open/read files.
Perhaps related follow-up question: Is there a way to inspect a module to see what other "submodules" are available? I sometimes like to do exploratory programming to just try things out, and being able to just "look" at an object or module and see what's in there is useful. Something like:
const std = @import("std");
@inspect(std);
If it helps, you can look at the std lib itself, and see which functions and sub-modules are public:
https://github.com/ziglang/zig/tree/master/std
As Merlyn suggests, I'd recommend looking through the std files (docgen isn't here yet, https://github.com/ziglang/zig/issues/21). Look in io.zig for opening/reading files.
If you'd like to take a look at some solutions, a few people have AOC repositories for zig. Just search "advent of code zig".
This issue did just give me an idea though: what if @typeInfo data included the doc comment? So I could e.g. do:
fn getDef(comptime T: type, field: []const u8) ?builtin.StructField {
const info = @typeInfo(T);
const defs = switch (info) {
builtin.TypeId.Struct => |s| s.defs,
builtin.TypeId.Union => |u| u.defs,
builtin.TypeId.Enum => |e| e.defs,
else => return null,
};
inline for (defs) |def| {
if (mem.eql(u8, def.name, field)) return def;
}
return null;
}
fn methodDocs(comptime T: type, field: []const u8) !?[]const u8 {
const def = getDefInfo(T, field) orelse return error.NoSuchMethod;
return def.docComment;
}
Are there plans to write a documentation in the following release of Zig ?
Hi @akatechis
Right now you have to read the source of std to find out the API.
For the solution to this I present to you the oldest open issue in the zig project: #21
Most helpful comment
This issue did just give me an idea though: what if
@typeInfodata included the doc comment? So I could e.g. do: