{"id":16909374,"url":"https://github.com/bluejekyll/enum-as-inner","last_synced_at":"2025-04-07T08:14:41.537Z","repository":{"id":33711145,"uuid":"160735013","full_name":"bluejekyll/enum-as-inner","owner":"bluejekyll","description":"Macros for deriving as functions to access Enums as their inner components","archived":false,"fork":false,"pushed_at":"2024-09-09T16:39:04.000Z","size":56,"stargazers_count":97,"open_issues_count":4,"forks_count":14,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-31T17:09:54.147Z","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":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bluejekyll.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2018-12-06T21:34:20.000Z","updated_at":"2025-02-27T02:17:16.000Z","dependencies_parsed_at":"2024-11-05T18:04:16.427Z","dependency_job_id":"71b6e890-93d2-4651-aac1-c2eb30b2329d","html_url":"https://github.com/bluejekyll/enum-as-inner","commit_stats":{"total_commits":74,"total_committers":11,"mean_commits":"6.7272727272727275","dds":0.6216216216216216,"last_synced_commit":"6770c8abd192beba72a2002ca9b3aa57f3db5f59"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluejekyll%2Fenum-as-inner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluejekyll%2Fenum-as-inner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluejekyll%2Fenum-as-inner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluejekyll%2Fenum-as-inner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bluejekyll","download_url":"https://codeload.github.com/bluejekyll/enum-as-inner/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247615377,"owners_count":20967184,"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-10-13T18:55:31.176Z","updated_at":"2025-04-07T08:14:41.501Z","avatar_url":"https://github.com/bluejekyll.png","language":"Rust","readme":"# enum-as-inner\n\nA deriving proc-macro for generating functions to automatically give access to the inner members of enum.\n\n## Basic unnamed field case\n\nThe basic case is meant for single item enums, like:\n\n```rust\nuse enum_as_inner::EnumAsInner;\n\n#[derive(Debug, EnumAsInner)]\nenum OneEnum {\n    One(u32),\n}\n```\n\nwhere the inner item can be retrieved with the `as_*()`/`as_*_mut()` or with the `into_*()` functions:\n\n```rust\nlet one = OneEnum::One(1);\n\nassert_eq!(*one.as_one().unwrap(), 1);\nassert_eq!(one.into_one().unwrap(), 1);\n\nlet mut one = OneEnum::One(2);\n\nassert_eq!(*one.as_one().unwrap(), 1);\nassert_eq!(*one.as_one_mut().unwrap(), 1);\nassert_eq!(one.into_one().unwrap(), 1);\n```\n\nwhere the result is either a reference for inner items or a tuple containing the inner items.\n\n## Unit case\n\nThis will return true if enum's variant matches the expected type\n\n```rust\nuse enum_as_inner::EnumAsInner;\n\n#[derive(EnumAsInner)]\nenum UnitVariants {\n    Zero,\n    One,\n    Two,\n}\n\nlet unit = UnitVariants::Two;\n\nassert!(unit.is_two());\n```\n\n## Mutliple, unnamed field case\n\nThis will return a tuple of the inner types:\n\n```rust\nuse enum_as_inner::EnumAsInner;\n\n#[derive(Debug, EnumAsInner)]\nenum ManyVariants {\n    One(u32),\n    Two(u32, i32),\n    Three(bool, u32, i64),\n}\n```\n\nAnd can be accessed like:\n\n```rust\nlet mut many = ManyVariants::Three(true, 1, 2);\n\nassert_eq!(many.as_three().unwrap(), (\u0026true, \u00261_u32, \u00262_i64));\nassert_eq!(many.as_three_mut().unwrap(), (\u0026mut true, \u0026mut 1_u32, \u0026mut 2_i64));\nassert_eq!(many.into_three().unwrap(), (true, 1_u32, 2_i64));\n```\n\n## Multiple, named field case\n\nThis will return a tuple of the inner types, like the unnamed option:\n\n```rust\nuse enum_as_inner::EnumAsInner;\n\n#[derive(Debug, EnumAsInner)]\nenum ManyVariants {\n    One{ one: u32 },\n    Two{ one: u32, two: i32 },\n    Three{ one: bool, two: u32, three: i64 },\n}\n```\n\nAnd can be accessed like:\n\n```rust\nlet mut many = ManyVariants::Three{ one: true, two: 1, three: 2 };\n\nassert_eq!(many.as_three().unwrap(), (\u0026true, \u00261_u32, \u00262_i64));\nassert_eq!(many.as_three_mut().unwrap(), (\u0026mut true, \u0026mut 1_u32, \u0026mut 2_i64));\nassert_eq!(many.into_three().unwrap(), (true, 1_u32, 2_i64));\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbluejekyll%2Fenum-as-inner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbluejekyll%2Fenum-as-inner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbluejekyll%2Fenum-as-inner/lists"}