{"id":17183396,"url":"https://github.com/geod24/minivariant","last_synced_at":"2026-01-05T12:51:34.106Z","repository":{"id":71216106,"uuid":"131978887","full_name":"Geod24/minivariant","owner":"Geod24","description":"Simple, focused variant library for the D programming language","archived":false,"fork":false,"pushed_at":"2024-02-08T00:02:10.000Z","size":11,"stargazers_count":5,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"v2.x.x","last_synced_at":"2025-01-30T03:42:48.117Z","etag":null,"topics":["dlang","library","variant"],"latest_commit_sha":null,"homepage":null,"language":"D","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/Geod24.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}},"created_at":"2018-05-03T10:22:09.000Z","updated_at":"2024-02-23T02:14:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"eda270ed-277b-4588-a841-20013bb2179b","html_url":"https://github.com/Geod24/minivariant","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Geod24%2Fminivariant","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Geod24%2Fminivariant/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Geod24%2Fminivariant/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Geod24%2Fminivariant/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Geod24","download_url":"https://codeload.github.com/Geod24/minivariant/tar.gz/refs/heads/v2.x.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245388327,"owners_count":20607161,"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","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":["dlang","library","variant"],"created_at":"2024-10-15T00:40:28.092Z","updated_at":"2026-01-05T12:51:34.067Z","avatar_url":"https://github.com/Geod24.png","language":"D","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Minivariant: Simple, focused variant library\n\n## Goal\n\nMinivariant provides a simple way to work with a tagged union.\nIt aims to provide a replacement for `std.variant.Algebraic`, which is built on top of `std.variant.Variant`.\n\nThe issue that spawned this effort was the inability of `Algebraic` to work with basic type conversion,\ne.g. it triggers a `static assert`ion failure to assign an `immutable int` to an `Algebraic` containing an `int`.\n\n## Overview\n\nThe main type is `geod24.variant : Variant`. It takes a tuple of accepted parameters:\n```D\nauto my_variant = Variant!(uint, char, bool, string)(\"Hello world\");\n```\nIt provides a pedestrian usage, via `isType` and `peek`, and a more structured approach via `visit`.\n\n## Example\n\nThis is the \"pedestrian\" usage:\n```d\n@safe unittest\n{\n    // Default construction is forbidden\n    // If you really need an empty Variant, use a dummy type\n    auto variant = Variant!(uint, bool)(uint(42));\n    // You can check the active type\n    assert(variant.isType!uint);\n    assert(!variant.isType!bool);\n    // Even with types which are not part of the variant\n    assert(!variant.isType!char);\n\n    // You can peek a value\n    if (auto valptr = variant.peek!uint)\n        assert(*valptr == 42);\n    if (auto valptr = variant.peek!bool)\n        assert(0);\n    if (auto valptr = variant.peek!int)\n        assert(0);\n}\n```\n\nThe visit approach needs an externally constructed overload set,\nso regular overloaded functions, either in a module or an aggregate are okay:\n```d\npublic class ValueAsString\n{\n    import std.format;\n    public static string opCall (T) (ref T value)\n    {\n        return format(\"%s %s\", T.stringof, value);\n    }\n}\n\n///\n@safe unittest\n{\n    auto variant = Variant!(byte, char, string, bool)(byte(42));\n    assert(variant.visit!ValueAsString == \"byte 42\");\n    variant = true;\n    assert(variant.visit!ValueAsString == \"bool true\");\n    variant = \"Hello World\";\n    assert(variant.visit!ValueAsString == \"string Hello World\");\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeod24%2Fminivariant","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgeod24%2Fminivariant","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeod24%2Fminivariant/lists"}