Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/Hejsil/itis

A small library for asking questions about types
https://github.com/Hejsil/itis

metaprogramming zig zig-library

Last synced: 3 months ago
JSON representation

A small library for asking questions about types

Awesome Lists containing this project

README

        

# itis

A small library for asking questions about types.

```zig
/// Example serialize function that uses `itis` to serialize ArrayList and ArrayHashMap.
pub fn serialize(writer: anytype, value: anytype) !void {
const T = @TypeOf(value);
if (comptime itis.anArrayList(T)) {
try writer.writeAll("[");
for (value.items) |item, i| {
if (i != 0)
try writer.writeAll(",");
try serialize(writer, item);
}
return writer.writeAll("]");
}
if (comptime itis.anArrayHashMap(T)) {
try writer.writeAll("{");
for (value.keys()) |key, i| {
const v = value.values()[i];
if (i != 0)
try writer.writeAll(",");

try serialize(writer, key);
try writer.writeAll(":");
try serialize(writer, v);
}
return writer.writeAll("}");
}

// The rest is left as an execise for the reader
}
```