{"id":19787057,"url":"https://github.com/tomboddaert/meta_match","last_synced_at":"2025-09-01T03:34:30.896Z","repository":{"id":214999786,"uuid":"737853209","full_name":"tomBoddaert/meta_match","owner":"tomBoddaert","description":"A zig module to match types","archived":false,"fork":false,"pushed_at":"2024-05-17T00:37:01.000Z","size":4089,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-28T14:09:01.666Z","etag":null,"topics":["metaprogramming","types","zig","ziglang"],"latest_commit_sha":null,"homepage":"https://tomboddaert.com/meta_match/","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tomBoddaert.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2024-01-01T18:25:12.000Z","updated_at":"2024-05-17T00:39:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"2288ca5e-0827-4beb-9709-23b40622fc9f","html_url":"https://github.com/tomBoddaert/meta_match","commit_stats":null,"previous_names":["tomboddaert/meta_match"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tomBoddaert/meta_match","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomBoddaert%2Fmeta_match","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomBoddaert%2Fmeta_match/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomBoddaert%2Fmeta_match/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomBoddaert%2Fmeta_match/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tomBoddaert","download_url":"https://codeload.github.com/tomBoddaert/meta_match/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomBoddaert%2Fmeta_match/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273069726,"owners_count":25040104,"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-09-01T02:00:09.058Z","response_time":120,"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":["metaprogramming","types","zig","ziglang"],"created_at":"2024-11-12T06:20:50.263Z","updated_at":"2025-09-01T03:34:30.873Z","avatar_url":"https://github.com/tomBoddaert.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"# meta_match\n\n`meta_match` is a [zig](https://ziglang.org/) module that can match types for you!\nIt is designed to assist with meta-programming of things like interfaces.\n\n## Adding meta_match to your project\nRun\n```sh\nzig fetch --save https://github.com/tomBoddaert/meta_match/archive/{commit}.tar.gz\n```\nWhere `{commit}` is replaced with the commit (e.g. `4129996211edd30b25c23454520fd78b2a70394b`).\n\n## Example: go-like interfaces\nInterfaces in go are implemented implicitly, this means that any type that has the required\nfunctions and fields.\n\n```zig\n/// An interface for deinitialising.\n///\n/// If the type does not have a `deinit` function, the `deinit` function\n/// does nothing.\npub fn Deinit(comptime T: type) type {\n    return struct {\n        // This matches a compatable 'deinit' function\n        const DeinitMatch = TypeMatch{\n            .Fn = \u0026FnMatch{\n                // Only accept zig and C functions\n                .calling_convention = .{ .options = \u0026.{ .Unspecified, .C, .Inline } },\n                // Don't accept C variadic functions\n                .is_var_args = false,\n                // It must return void\n                .return_type = TypeMatch{ .Void = {} },\n                .params = \u0026.{\n                    // It must have a single pointer parameter\n                    // Note that the 'constness' of this pointer is not specified,\n                    // so functions that take '*const T' will also be accepted.\n                    ParamMatch{\n                        .type = TypeMatch{\n                            .Pointer = \u0026PointerMatch{\n                                // The pointer must point to one value\n                                .size = .{ .options = \u0026.{Type.Pointer.Size.One} },\n                                // It must not be volatile\n                                .is_volatile = false,\n                                // It must be pointing to a 'T'\n                                .child = TypeMatch{ .by_type = T },\n                                // It must not have a sentinel\n                                // Note that if this was just 'null', meta_match would not\n                                // check it.\n                                .sentinel = @as(?*const anyopaque, null),\n                            },\n                        },\n                    },\n                },\n            },\n        };\n\n        /// The MetaMatch expression used to determine 'has_deinit'.\n        pub const MetaMatch = TypeMatch{\n            .container = \u0026ContainerMatch{\n                // It must be a container with a 'deinit' declaration matching 'DeinitMatch' above\n                .decls = \u0026.{DeclarationMatch{ .name = \"deinit\", .type = DeinitMatch }},\n            },\n        };\n\n        /// `true` if `T` has a `deinit` function.\n        pub const has_deinit: bool = MetaMatch.match(T);\n\n        /// Deinitialise a value.\n        pub inline fn deinit(value: *T) void {\n            if (has_deinit) {\n                T.deinit(value);\n            }\n        }\n    };\n}\n\ntest {\n    try testing.expect(!Deinit(u8).has_deinit);\n    var n: u8 = 5;\n    // This will do nothing\n    Deinit(u8).deinit(\u0026n);\n\n    const S = struct {\n        pub fn deinit(_: *@This()) void {}\n    };\n    try testing.expect(Deinit(S).has_deinit);\n    var s = S{};\n    // This will run the deinit function\n    Deinit(S).deinit(\u0026s);\n}\n```\n\nIn this example, if 'deinit' is called with a type that does not have a 'deinit' function, nothing happens but\nyou could add a compile error, or you could run a default function.\nIf 'deinit' is run with a type that does have a matching 'deinit' function, then the type's 'deinit' function is called.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomboddaert%2Fmeta_match","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomboddaert%2Fmeta_match","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomboddaert%2Fmeta_match/lists"}