{"id":18364205,"url":"https://github.com/boxbeam/constant_pool","last_synced_at":"2025-04-10T09:59:13.865Z","repository":{"id":111830754,"uuid":"453234529","full_name":"boxbeam/constant_pool","owner":"boxbeam","description":"A rust macro for making constant pools much like Java enums","archived":false,"fork":false,"pushed_at":"2022-01-30T18:34:16.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-15T19:48:41.352Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","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/boxbeam.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}},"created_at":"2022-01-28T22:25:45.000Z","updated_at":"2022-01-28T22:26:29.000Z","dependencies_parsed_at":"2023-06-04T03:30:55.023Z","dependency_job_id":null,"html_url":"https://github.com/boxbeam/constant_pool","commit_stats":null,"previous_names":["boxbeam/constant_pool"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boxbeam%2Fconstant_pool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boxbeam%2Fconstant_pool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boxbeam%2Fconstant_pool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boxbeam%2Fconstant_pool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/boxbeam","download_url":"https://codeload.github.com/boxbeam/constant_pool/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248198864,"owners_count":21063626,"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":[],"created_at":"2024-11-05T23:09:35.224Z","updated_at":"2025-04-10T09:59:13.843Z","avatar_url":"https://github.com/boxbeam.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# constant_pool\nA rust macro for making constant pools much like Java enums\n\n# Usage\nTo define a constant pool, you must first define a struct or tuple struct type.\n\nIf you are defining a struct type, it must have a field of type `\u0026str` called `name`. If it is a tuple struct, the first value must be of type `\u0026str`.\n\nExamples:\n\n```rs\nstruct Color(\u0026'static str, u8, u8, u8);\n```\n\n```rs\nstruct Team {\n  name: \u0026'static str,\n  number: u8\n}\n```\n\nOnce your struct is defined, you can define the constant pool using the `constant_pool!` macro:\n\n```rs\nconstant_pool! {\n  pub Colors: Color {\n    RED(255, 0, 0),\n    BLUE(0, 0, 255),\n    GREEN(0, 255, 0),\n    YELLOW(0, 255, 255)\n  }\n}\n```\n\n```rs\nconstant_pool! {\n  pub Teams: Team {\n    WHITE{number: 1},\n    BLACK{number: 2},\n    ORANGE{number: 3}\n  }\n}\n```\n\nThe name of the constant pool is defined, followed by the struct type it will use. Once defined, it creates a namespace with a module for the constant pool, populating it with all the constants you defined. For the above examples, you could access `Color::RED` and `Team::WHITE` respectively.\n\nAdditionally, the constant pool generates a slice containing all of the constant values, under `Namespace::values`. For our examples, this will be `Color::values` and `Team::values`. It will also generate a function to get any of the values by name, returning an `Option\u003c\u0026T\u003e`:\n\n```rs\nlet color: \u0026Color = Color::by_name(\"RED\").unwrap();\nlet team = Team::by_name(\"ORANGE\").unwrap();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboxbeam%2Fconstant_pool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fboxbeam%2Fconstant_pool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboxbeam%2Fconstant_pool/lists"}