{"id":35157566,"url":"https://github.com/captkirk88/zevy-reflect","last_synced_at":"2025-12-28T17:05:22.289Z","repository":{"id":328093615,"uuid":"1111306069","full_name":"captkirk88/zevy-reflect","owner":"captkirk88","description":"A reflection library in Zig with utilities covering change detection and interface validation and vtable generation using real structs.","archived":false,"fork":false,"pushed_at":"2025-12-19T02:08:32.000Z","size":134,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-12-19T12:59:18.935Z","etag":null,"topics":["reflection","zig","zig-library","zig-package","zig-programming-language","ziglang"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/captkirk88.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-12-06T17:17:08.000Z","updated_at":"2025-12-19T02:08:36.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/captkirk88/zevy-reflect","commit_stats":null,"previous_names":["captkirk88/zevy-reflect"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/captkirk88/zevy-reflect","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/captkirk88%2Fzevy-reflect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/captkirk88%2Fzevy-reflect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/captkirk88%2Fzevy-reflect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/captkirk88%2Fzevy-reflect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/captkirk88","download_url":"https://codeload.github.com/captkirk88/zevy-reflect/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/captkirk88%2Fzevy-reflect/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28101614,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-28T02:00:05.685Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["reflection","zig","zig-library","zig-package","zig-programming-language","ziglang"],"created_at":"2025-12-28T17:04:20.247Z","updated_at":"2025-12-28T17:05:22.270Z","avatar_url":"https://github.com/captkirk88.png","language":"Zig","readme":"# zevy-reflect\n\nA lightweight reflection and change detection library for Zig.\n\n[![Zig Version](https://img.shields.io/badge/zig-0.15.1+-blue.svg)](https://ziglang.org/)\n\n## Features\n\n- **Runtime Type Information**: Get detailed type information at runtime including fields, functions, and nested types\n- **Interface Validation**: Compile-time validation of interface implementations with clear error messages\n    - **VTable Generation**: Create vtables for dynamic dispatch based on interfaces, with support for interface extension. Tested using std.mem.Allocation.VTable interface.\n- **Change Detection**: Track changes to struct fields with minimal memory overhead (8 bytes)\n- **Zero Dependencies**: Pure Zig implementation with no external dependencies\n\n## Installation\n\nAdd to your `build.zig.zon`:\n\n```bash\nzig fetch --save git+https://github.com/captkirk88/zevy-reflect\n```\n\nThen in your `build.zig`:\n\n```zig\nconst zevy_reflect = b.dependency(\"zevy_reflect\", .{\n    .branch_quota = 20000, // Optional: increase eval branch quota for complex reflection (default: 10000)\n});\nexe.root_module.addImport(\"zevy_reflect\", zevy_reflect.module(\"zevy_reflect\"));\n```\n\n## Quick Start\n\n### Reflection\n\nThis library provides both lightweight (shallow) runtime `TypeInfo` and a small set of helpers to query type structure without blowing up comptime.\n\n```zig\nconst reflect = @import(\"zevy_reflect\");\nconst std = @import(\"std\");\n\nconst MyStruct = struct {\n    id: u32,\n    name: []const u8,\n    active: bool,\n\n    pub fn getId(self: @This()) u32 { return self.id; }\n};\n\ncomptime {\n    const info = reflect.getTypeInfo(MyStruct);\n    std.debug.print(\"Name: {s}, Size: {d}\\n\", .{ info.name, info.size });\n\n    // Field checks (comptime-safe helpers):\n    try std.testing.expect(comptime reflect.hasField(MyStruct, \"id\"));\n    try std.testing.expect(comptime reflect.hasFunc(MyStruct, \"getId\"));\n\n    // List field names at comptime\n    const fields = reflect.getFields(MyStruct);\n    inline for (fields) |f| std.debug.print(\"field: {s}\\n\", .{ f });\n}\n\n// Runtime: use TypeInfo to introspect dynamic metadata (shallow info avoids recursion)\nconst ti = reflect.getTypeInfo(MyStruct);\nstd.debug.print(\"Runtime fields: {d}\\n\", .{ ti.fields.len });\n\n// Construct a value using `TypeInfo.new` from a tuple literal (comptime API)\ncomptime {\n    const ti_comp = reflect.getTypeInfo(MyStruct);\n    const instance_default = ti_comp.new(.{});\n    const instance_override = ti_comp.new(.{ .id = 10, .name = \"bob\" });\n    try std.testing.expectEqual(@as(u32, 10), instance_override.id);\n}\n```\n\nNotes:\n- `getTypeInfo` returns shallow field and function metadata suitable for runtime use.\n- `TypeInfo.new` is a comptime helper that constructs values from tuple literals; useful for code generation and tests.\n\n### Interface Validation and VTable\n\n`Template(...)` provides a compile-time validator and a typed vtable generator. Useful when you want an explicit interface and a vtable for dynamic dispatch. You can also obtain a convenience bound interface instance with `Template.interface(ImplType, \u0026instance)`.\n\nThis is a different approach to interfaces in Zig.  Hopefully more useful and generally easier to integrate.\n\nSee [common_interfaces.zig](src/common_interfaces.zig) for a examples.\n\n### Change Detection\n\n`Change(T)` is a tiny tracker that hashes trackable fields and detects modifications. Fields beginning with `_` are ignored.\n\n```zig\nconst reflect = @import(\"zevy_reflect\");\nconst std = @import(\"std\");\n\nconst Player = struct {\n    health: i32,\n    score: u32,\n    _internal_id: u64, // ignored by Change\n};\n\nvar player = Player{ .health = 100, .score = 0, ._internal_id = 123 };\nvar tracker = reflect.Change(Player).init(player);\n\n// Mutate through `get()` (mutable) and finish when processed\nvar data = tracker.get();\ndata.health = 80;\ndata.score = 100;\n\nif (tracker.isChanged()) {\n    std.debug.print(\"Player changed: {d}\\n\", .{ tracker.getConst().score });\n    tracker.finish();\n}\n```\n\n\u003e [!WARNING]\n\u003e The tracker compares raw bytes for tracked fields; pointer/slice/array contents are hashed as their pointer/length/contents as appropriate. Be cautious with non-stable data (e.g., transient pointers).\n\n## Contributing\n\n1. Fork the repository\n2. Create a feature branch\n3. Add tests for any new functionality\n4. Ensure all tests pass: `zig build test`\n5. Submit a pull request\n\n## Related Projects\n\n- [zevy-ecs](https://github.com/captkirk88/zevy-ecs) - Entity Component System framework that uses zevy-reflect.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaptkirk88%2Fzevy-reflect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcaptkirk88%2Fzevy-reflect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaptkirk88%2Fzevy-reflect/lists"}