Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standard library docs? #2539

Closed
akatechis opened this issue May 22, 2019 · 5 comments
Closed

Standard library docs? #2539

akatechis opened this issue May 22, 2019 · 5 comments

Comments

@akatechis
Copy link

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);
@merlynmg
Copy link

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

@benjif
Copy link

benjif commented May 23, 2019

As Merlyn suggests, I'd recommend looking through the std files (docgen isn't here yet, #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".

@daurnimator
Copy link
Collaborator

daurnimator commented May 23, 2019

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;
}

@ducdetronquito
Copy link
Contributor

ducdetronquito commented May 23, 2019

Are there plans to write a documentation in the following release of Zig ?

@andrewrk
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants