Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/Hejsil/itis
- Owner: Hejsil
- License: mit
- Archived: true
- Created: 2022-05-31T22:35:55.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-09-13T12:17:37.000Z (5 months ago)
- Last Synced: 2024-09-14T02:08:30.638Z (5 months ago)
- Topics: metaprogramming, zig, zig-library
- Language: Zig
- Homepage:
- Size: 13.7 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
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
}
```