{"id":27148800,"url":"https://github.com/andogq/assert_layout","last_synced_at":"2026-02-16T00:32:14.217Z","repository":{"id":285918261,"uuid":"959777751","full_name":"andogq/assert_layout","owner":"andogq","description":"Assert struct layouts, including field sizes and offsets.","archived":false,"fork":false,"pushed_at":"2025-04-03T10:42:57.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-23T18:20:55.715Z","etag":null,"topics":["assert","encoding","field-size","layout","macro","memory-layout","offset","proc-macro","rust","sizeof","static-assertions","struct-layout"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/assert_layout","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/andogq.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","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,"publiccode":null,"codemeta":null}},"created_at":"2025-04-03T10:39:21.000Z","updated_at":"2025-04-03T11:30:18.000Z","dependencies_parsed_at":"2025-04-10T01:28:42.186Z","dependency_job_id":null,"html_url":"https://github.com/andogq/assert_layout","commit_stats":null,"previous_names":["andogq/assert_layout"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/andogq/assert_layout","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andogq%2Fassert_layout","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andogq%2Fassert_layout/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andogq%2Fassert_layout/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andogq%2Fassert_layout/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andogq","download_url":"https://codeload.github.com/andogq/assert_layout/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andogq%2Fassert_layout/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29494989,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-16T00:16:34.147Z","status":"ssl_error","status_checked_at":"2026-02-16T00:15:26.759Z","response_time":118,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["assert","encoding","field-size","layout","macro","memory-layout","offset","proc-macro","rust","sizeof","static-assertions","struct-layout"],"created_at":"2025-04-08T12:34:29.681Z","updated_at":"2026-02-16T00:32:14.211Z","avatar_url":"https://github.com/andogq.png","language":"Rust","readme":"# assert_layout\n\n***Assert struct layouts, including field sizes and offsets.***\n\n`assert_layout` provides a single proc-macro which will perform compile-time assertions for certain\nqualities of a struct. In addition to field size and offset, it's also possible to provide concrete\ntypes for generics and assert that the layout still holds.\n\n## Overview\n\nStruct containers can use the `size` assertion to assert the size of the struct.\n\n```rust\nuse assert_layout::assert_layout;\n\n#[assert_layout(size = 1)]\n#[repr(packed)]\nstruct MyStruct {\n    field: u8,\n}\n```\n\nSimilarly, each field can use the `size` and `offset` assertions.\n\n```rust\nuse assert_layout::assert_layout;\n\n#[assert_layout(size = 5)]\n#[repr(packed)]\nstruct MyStruct {\n    #[assert_layout(offset = 0, size = 1)]\n    field: u8,\n\n    #[assert_layout(offset = 2, size = 4)]\n    another_field: f32,\n}\n```\n\n### Generics\n\nIf the struct contains generics, concrete types can be provided for assertions using `generics`.\nFor instance, the following assertion would expand with `T = u32`.\n\n```rust\nuse assert_layout::assert_layout;\n\n#[assert_layout(size = 4, generics = \"u32\")]\n#[repr(packed)]\nstruct MyStruct\u003cT\u003e {\n    #[assert_layout(offset = 0, size = 4)]\n    field: T,\n}\n```\n\nMultiple generic parameters can by provided with commas between them, in addition to consts (in the\nsame manner as `MyStruct\u003c...\u003e`).\n\n```rust\nuse assert_layout::assert_layout;\n\n#[assert_layout(size = 64, generics = \"8, f64\")]\n#[repr(packed)]\nstruct MyStruct\u003cconst N: usize, T\u003e {\n    #[assert_layout(offset = 0, size = 64)]\n    field: [T; N],\n}\n```\n\nThe `generics` attribute can be provided multiple times in order to assert different combinations\nof generics.\n\n```rust\nuse assert_layout::assert_layout;\n\n#[assert_layout(size = 12, generics = \"u32, u64\", generics = \"i32, i64\")]\n#[repr(packed)]\nstruct MyStruct\u003cT, U\u003e {\n    #[assert_layout(offset = 0, size = 4)]\n    field: T,\n\n    #[assert_layout(offset = 4, size = 8)]\n    another_field: U,\n}\n```\n\n### Namespaces\n\nSometimes generic combinations will not be compatible with each other, so namespaces can be used to\nisolate the assertions. A namespace is created using `namespace(...)`, where `namespace` is a\nunique identifier for the namepsace, and the previously described assertions (`generics`, `offset`,\n`size`) are within the brackets. Everything within the namespace will be asserted in isolation.\n\n```rust\nuse assert_layout::assert_layout;\n\n#[assert_layout(little(size = 4, generics = \"u32\"), big(size = 8, generics = \"u64\"))]\n#[repr(packed)]\nstruct MyStruct\u003cT\u003e {\n    #[assert_layout(little(offset = 0, size = 4), big(offset = 0, size = 8))]\n    field: T,\n}\n```\n\nIf there are common assertions between the namespaces (such as `offset = 0` above), they can be\nomitted from the namespace and asserted at the top level.\n\n```rust\nuse assert_layout::assert_layout;\n\n#[assert_layout(\n    generics = \"u32\",\n    generics = \"u64\",\n    little(size = 4, generics = \"u32\"),\n    big(size = 8, generics = \"u64\")\n)]\n#[repr(packed)]\nstruct MyStruct\u003cT\u003e {\n    #[assert_layout(offset = 0, little(size = 4), big(size = 8))]\n    field: T,\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandogq%2Fassert_layout","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandogq%2Fassert_layout","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandogq%2Fassert_layout/lists"}