{"id":19035826,"url":"https://github.com/adinack/bundle","last_synced_at":"2025-04-17T14:33:27.819Z","repository":{"id":204746216,"uuid":"712556932","full_name":"AdinAck/bundle","owner":"AdinAck","description":"A multi-type container with a static size.","archived":true,"fork":false,"pushed_at":"2024-02-10T00:43:03.000Z","size":42,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-21T21:38:44.322Z","etag":null,"topics":["embedded-rust","no-std","static-types"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/AdinAck.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}},"created_at":"2023-10-31T17:48:12.000Z","updated_at":"2024-08-18T03:18:18.000Z","dependencies_parsed_at":"2024-02-10T01:42:28.244Z","dependency_job_id":null,"html_url":"https://github.com/AdinAck/bundle","commit_stats":null,"previous_names":["adinack/bundle","adinack/bundle-proc-macros"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AdinAck%2Fbundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AdinAck%2Fbundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AdinAck%2Fbundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AdinAck%2Fbundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AdinAck","download_url":"https://codeload.github.com/AdinAck/bundle/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249348707,"owners_count":21255308,"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":["embedded-rust","no-std","static-types"],"created_at":"2024-11-08T21:52:16.734Z","updated_at":"2025-04-17T14:33:27.556Z","avatar_url":"https://github.com/AdinAck.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bundle\nA multi-type container with a static size.\n\n## no_std\n\nThis crate is intended for use in `no_std` environments.\n\n# Motivation\n\nTrait objects require dynamic memory allocation since the concrete type being dispatched is not known until runtime.\n\nFor `no_std` environments, a global allocator may be limited, or not available at all. But dynamic dispatch may still be desired.\n\n# Solution\n\nThis crate provides an attribute macro for generating an enum type that contains a finite set of concrete types.\n\nEach variant of the enum corresponds to a type, in the form of a tuple variant.\n\nRust enums occupy as much space as the largest variant:\n\n```rust\nenum MultipleTypes {\n  A(A),\n  B(B),\n  C(C),\n  D(D)\n}\n```\n\nMemory:\n\n```\n  |#     \u003c- A\n  |###   \u003c- B\n  |##    \u003c- C\n  |##### \u003c- D\n##|##### \u003c Total size\n ^\n |\npadding/tag\n```\n\n# Usage\n## Basic\n\nTo create a bundle, simply mark an enum as a such:\n\n```rust\ntrait Foo {\n    fn bar(\u0026self) -\u003e u8;\n}\n\n#[bundle]\nenum MyBundle {\n  FirstType,\n  SecondType,\n  ThirdType\n}\n```\n\nNow you can invoke methods defined by the shared trait:\n\n```rust\nimpl Foo for FirstType {\n    fn bar(\u0026self) -\u003e u8 {\n        0\n    }\n}\n\nimpl Foo for SecondType {\n    fn bar(\u0026self) -\u003e u8 {\n        1\n    }\n}\n\nimpl Foo for ThirdType {\n    fn bar(\u0026self) -\u003e u8 {\n        2\n    }\n}\n\nlet bundle: MyBundle = { /* fetch bundle from somewhere... */ }\n\nlet bar = use_my_bundle!(bundle, |inner| { inner.bar() }); // will be 0, 1, or 2 depending on what's in the bundle\n```\n\n## Other macros\n\nBundles can still be used with other macros as long as the bundle is the first one executed.\n\nFor example, use with `derive` where types `A`, `B` and `C` implement `Clone`:\n\n```rust\n#[bundle] // this goes first so derive sees the transformed enum\n#[derive(Clone)]\nenum MyBundle {\n    A,\n    B,\n    C,\n}\n```\n\n## Generics\n\nIf generics are required for your bundle, you can add them like so:\n\n```rust\n#[bundle]\nenum MyBundle\u003cT: Trait1, U: Trait2\u003e {\n    A(A\u003cT\u003e), // notice you must now create the tuple variant yourself\n    B,\n    C(C\u003cU\u003e),\n}\n```\n\n# Design Considerations\n\n## Safety\n\nThe `#[bundle]` macro cannot generate unsafe code.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadinack%2Fbundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadinack%2Fbundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadinack%2Fbundle/lists"}