{"id":15692666,"url":"https://github.com/zephraph/typesets","last_synced_at":"2025-05-07T23:46:34.346Z","repository":{"id":45921955,"uuid":"426680209","full_name":"zephraph/typesets","owner":"zephraph","description":null,"archived":false,"fork":false,"pushed_at":"2021-12-17T01:26:21.000Z","size":47,"stargazers_count":7,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-13T09:06:18.693Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zephraph.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}},"created_at":"2021-11-10T15:42:14.000Z","updated_at":"2022-12-07T14:57:59.000Z","dependencies_parsed_at":"2022-09-26T21:40:14.252Z","dependency_job_id":null,"html_url":"https://github.com/zephraph/typesets","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zephraph%2Ftypesets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zephraph%2Ftypesets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zephraph%2Ftypesets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zephraph%2Ftypesets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zephraph","download_url":"https://codeload.github.com/zephraph/typesets/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252973619,"owners_count":21834105,"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-03T18:37:32.412Z","updated_at":"2025-05-07T23:46:34.327Z","avatar_url":"https://github.com/zephraph.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Typesets\n\nThis library aims to provide a set of macros that help remove the boilerplate of expressing relationships between different types.\n\n## Supertype\n\nThis derive macro provides the ability to generate enums which are a subset of the derived type.\n\nTo use, simply include the `Supertype` and denote which variants should go to which derived enums by the `subtype` attr.\n\n```rust\n#[derive(Supertype)]\npub enum MyExpansiveType {\n  #[subtype(MyNarrowerType, MyOtherType)]\n  State1(String),\n  #[subtype(MyNarrowerType)]\n  State2(u8),\n  #[subtype(MyOtherType)]\n  State3,\n  State4\n}\n```\n\nThe above will expand to...\n\n```rust\npub enum MyExpansiveType {\n  State1(String),\n  State2(u8),\n  State3,\n  State4\n}\n\npub enum MyNarrowerType {\n  State1(String),\n  State2(u8)\n}\n\nimpl TryFrom\u003cMyExpansiveType\u003e for MyNarrowerType {\n  type Error = crate::TypesetsError;\n  fn try_from(parent: MyExpansiveType) -\u003e Result\u003cSelf, Self::Error\u003e {\n    match parent {\n      MyExpansiveType::State1(v0) =\u003e Ok(MyNarrowerType::State1(v0)),\n      MyExpansiveType::State2(v0) =\u003e Ok(MyNarrowerType::State2(v0)),\n      other =\u003e Err(Self::Error::EnumNoOverlap {\n        supertype: \"MyExpansiveType\",\n        subtype: \"MyNarrowerType\",\n        variant: format!(\"{:?}\", other)\n      })\n    }\n  }\n}\n\nimpl From\u003cMyNarrowerType\u003e for MyExpansiveType {\n  fn from(child: MyNarrowerType) -\u003e Self {\n    match child {\n      MyNarrowerType::State1(v0) =\u003e MyExpansiveType::State1(v0),\n      MyNarrowerType::State2(v0) =\u003e MyExpansiveType::State2(v0),\n    }\n  }\n}\n\npub enum MyOtherType {\n  State1(String),\n  State3,\n}\n\n\nimpl TryFrom\u003cMyExpansiveType\u003e for MyOtherType {\n  type Error = crate::TypesetsError;\n  fn try_from(parent: MyExpansiveType) -\u003e Result\u003cSelf, Self::Error\u003e {\n    match parent {\n      MyExpansiveType::State1(v0) =\u003e Ok(MyOtherType::State1(v0)),\n      MyExpansiveType::State2(v0) =\u003e Ok(MyOtherType::State2(v0)),\n      other =\u003e Err(Self::Error::EnumNoOverlap {\n        supertype: \"MyExpansiveType\",\n        subtype: \"MyOtherType\",\n        variant: format!(\"{:?}\", other)\n      })\n    }\n  }\n}\n\nimpl From\u003cMyOtherType\u003e for MyExpansiveType {\n  fn from(child: MyOtherType) -\u003e Self {\n    match child {\n      MyOtherType::State1(v0) =\u003e MyExpansiveType::State1(v0),\n      MyOtherType::State2(v0) =\u003e MyExpansiveType::State2(v0),\n    }\n  }\n}\n```\n\n## Subtype\n\nSometimes you'll want to describe that a given enum is a subtype of another enum without actually having access to the original enum.\nThis can be accomplished with the `Subtype` derive macro and the `subtype_of` attribute.\n\n```\n#[derive(Subtype)]\n#[subtype_of(SomeSuperType)]\nenum MySubType {\n  Variant1,\n  Variant2(u8)\n}\n```\n\nwhich will expand to\n\n```rust\nenum MySubType {\n  Variant1,\n  Variant2(u8)\n}\n\nimpl TryFrom\u003cSomeSuperType\u003e for MySubType {\n  type Error = crate::typesets::subtype::SubtypeError;\n\n  fn try_from(parent: SomeSuperType) -\u003e Result\u003cSelf, Self::Error\u003e {\n    match parent {\n      SomeSuperType::Variant1 =\u003e MySubType::Variant1,\n      SomeSuperType::Variant2(v0) =\u003e MySubType::Variant2(v0),\n      other =\u003e Self::Error::EnumNoOverlap {\n        supertype: \"SomeSuperType\",\n        subtype: \"MySubType\",\n        variant: format!(\"{:?}\", other)\n      }\n    }\n  }\n}\n\nimpl From\u003cMySubType\u003e for SomeSuperType {\n  fn for(child: MySubType) -\u003e Self {\n    match child {\n      MySubType::Variant1 =\u003e MySupertype::Variant1,\n      MySubType::Variant2(v0) =\u003e MySupertype::Variant2(v0),\n    }\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzephraph%2Ftypesets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzephraph%2Ftypesets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzephraph%2Ftypesets/lists"}