{"id":13599872,"url":"https://github.com/nvzqz/static-assertions","last_synced_at":"2025-04-04T20:15:37.900Z","repository":{"id":23898451,"uuid":"100129252","full_name":"nvzqz/static-assertions","owner":"nvzqz","description":"Ensure correct assumptions about constants, types, and more in Rust","archived":false,"fork":false,"pushed_at":"2023-11-18T10:20:29.000Z","size":560,"stargazers_count":576,"open_issues_count":35,"forks_count":23,"subscribers_count":17,"default_branch":"master","last_synced_at":"2024-10-29T16:20:02.502Z","etag":null,"topics":["assert","compile-time","rust","static-assertions","testing"],"latest_commit_sha":null,"homepage":"https://docs.rs/static_assertions","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/nvzqz.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":["nvzqz"],"patreon":"nvzqz","custom":["https://www.paypal.me/nvzqz"]}},"created_at":"2017-08-12T18:02:22.000Z","updated_at":"2024-10-23T16:21:55.000Z","dependencies_parsed_at":"2022-07-25T13:51:59.735Z","dependency_job_id":"b9908472-abae-4b1f-9943-c7f364b4dc9e","html_url":"https://github.com/nvzqz/static-assertions","commit_stats":null,"previous_names":["nvzqz/static-assertions-rs"],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nvzqz%2Fstatic-assertions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nvzqz%2Fstatic-assertions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nvzqz%2Fstatic-assertions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nvzqz%2Fstatic-assertions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nvzqz","download_url":"https://codeload.github.com/nvzqz/static-assertions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247242681,"owners_count":20907134,"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":["assert","compile-time","rust","static-assertions","testing"],"created_at":"2024-08-01T17:01:14.972Z","updated_at":"2025-04-04T20:15:37.880Z","avatar_url":"https://github.com/nvzqz.png","language":"Rust","readme":"[![Banner](https://raw.githubusercontent.com/nvzqz/static-assertions-rs/assets/Banner.png)](https://github.com/nvzqz/static-assertions-rs)\n\n\u003cdiv align=\"center\"\u003e\n    \u003ca href=\"https://crates.io/crates/static_assertions\"\u003e\n        \u003cimg src=\"https://img.shields.io/crates/v/static_assertions.svg\" alt=\"Crates.io\"\u003e\n        \u003cimg src=\"https://img.shields.io/crates/d/static_assertions.svg\" alt=\"Downloads\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/nvzqz/static-assertions-rs/actions?query=workflow%3ACI\"\u003e\n        \u003cimg src=\"https://github.com/nvzqz/static-assertions-rs/workflows/CI/badge.svg\" alt=\"Build Status\"\u003e\n    \u003c/a\u003e\n    \u003cimg src=\"https://img.shields.io/badge/rustc-^1.37.0-blue.svg\" alt=\"rustc ^1.37.0\"\u003e\n    \u003cbr\u003e\n    \u003ca href=\"https://www.patreon.com/nvzqz\"\u003e\n        \u003cimg src=\"https://c5.patreon.com/external/logo/become_a_patron_button.png\" alt=\"Become a Patron!\" height=\"35\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://www.paypal.me/nvzqz\"\u003e\n        \u003cimg src=\"https://buymecoffee.intm.org/img/button-paypal-white.png\" alt=\"Buy me a coffee\" height=\"35\"\u003e\n    \u003c/a\u003e\n\u003c/div\u003e\n\nCompile-time assertions for Rust, brought to you by\n[Nikolai Vazquez](https://twitter.com/NikolaiVazquez).\n\nThis library lets you ensure correct assumptions about constants, types, and\nmore. See the [docs] and [FAQ](#faq) for more info!\n\n## Installation\n\nThis crate is available\n[on crates.io](https://crates.io/crates/static_assertions) and can be used by\nadding the following to your project's\n[`Cargo.toml`](https://doc.rust-lang.org/cargo/reference/manifest.html):\n\n```toml\n[dependencies]\nstatic_assertions = \"1.1.0\"\n```\n\nand this to your crate root (`main.rs` or `lib.rs`):\n\n```rust\n#[macro_use]\nextern crate static_assertions;\n```\n\n## Usage\n\nThis crate exposes the following macros:\n- [`assert_cfg!`]\n- [`assert_eq_align!`]\n- [`assert_eq_size!`]\n- [`assert_eq_size_ptr!`]\n- [`assert_eq_size_val!`]\n- [`assert_fields!`]\n- [`assert_impl_all!`]\n- [`assert_impl_any!`]\n- [`assert_impl_one!`]\n- [`assert_not_impl_all!`]\n- [`assert_not_impl_any!`]\n- [`assert_obj_safe!`]\n- [`assert_trait_sub_all!`]\n- [`assert_trait_super_all!`]\n- [`assert_type_eq_all!`]\n- [`assert_type_ne_all!`]\n- [`const_assert!`]\n- [`const_assert_eq!`]\n- [`const_assert_ne!`]\n\n## FAQ\n\n- **Q:** When would I want to use this?\n\n  **A:** This library is useful for when wanting to ensure properties of\n  constants, types, and traits.\n\n  Basic examples:\n\n  - With the release of 1.39, `str::len` can be called in a `const`\n    context. Using [`const_assert!`], one can check that a string generated from\n    elsewhere is of a given size:\n\n    ```rust\n    const DATA: \u0026str = include_str!(\"path/to/string.txt\");\n\n    const_assert!(DATA.len() \u003c 512);\n    ```\n\n  - Have a type that absolutely must implement certain traits? With\n    [`assert_impl_all!`], one can ensure this:\n\n    ```rust\n    struct Foo {\n        value: // ...\n    }\n\n    assert_impl_all!(Foo: Send, Sync);\n    ```\n\n- **Q:** How can I contribute?\n\n  **A:** A couple of ways! You can:\n\n  - Attempt coming up with some form of static analysis that you'd like to see\n    implemented. Create a [new issue] and describe how you'd imagine your\n    assertion to work, with example code to demonstrate.\n\n  - Implement your own static assertion and create a [pull request].\n\n  - Give feedback. What are some pain points? Where is it unpleasant?\n\n  - Write docs. If you're familiar with how this library works, sharing your\n    knowledge with the rest its users would be great!\n\n- **Q:** Will this affect my compiled binary?\n\n  **A:** Nope! There is zero runtime cost to using this because all checks are\n  at compile-time, and so no code is emitted to run.\n\n- **Q:** Will this affect my compile times?\n\n  **A:** Likely not by anything perceivable. If this is a concern, this library\n  can be put in `dev-dependencies`:\n\n  ```toml\n  [dev-dependencies]\n  static_assertions = \"1.1.0\"\n  ```\n\n  and then assertions can be conditionally run behind `#[cfg(test)]`:\n\n  ```rust\n  #[cfg(test)]\n  const_assert_eq!(MEANING_OF_LIFE, 42);\n  ```\n\n  However, the assertions will only be checked when running `cargo test`. This\n  somewhat defeats the purpose of catching false static conditions up-front with\n  a compilation failure.\n\n- **Q:** What is `const _`?\n\n  **A:** It's a way of creating an unnamed constant. This is used so that macros\n  can be called from a global scope without requiring a scope-unique label. This\n  library makes use of the side effects of evaluating the `const` expression.\n  See the feature's\n  [tracking issue](https://github.com/rust-lang/rust/issues/54912)\n  and\n  [issue #1](https://github.com/nvzqz/static-assertions-rs/issues/1)\n  for more info.\n\n## Changes\n\nSee [`CHANGELOG.md`](https://github.com/nvzqz/static-assertions-rs/blob/master/CHANGELOG.md)\nfor a complete list of what has changed from one version to another.\n\n## License\n\nThis project is released under either:\n\n- [MIT License](https://github.com/nvzqz/static-assertions-rs/blob/master/LICENSE-MIT)\n\n- [Apache License (Version 2.0)](https://github.com/nvzqz/static-assertions-rs/blob/master/LICENSE-APACHE)\n\nat your choosing.\n\n[new issue]:    https://github.com/nvzqz/static-assertions-rs/issues/new\n[pull request]: https://github.com/nvzqz/static-assertions-rs/pulls\n[docs]:         https://docs.rs/static_assertions\n\n[`assert_cfg!`]:             https://docs.rs/static_assertions/1.1.0/static_assertions/macro.assert_cfg.html\n[`assert_eq_align!`]:        https://docs.rs/static_assertions/1.1.0/static_assertions/macro.assert_eq_align.html\n[`assert_eq_size!`]:         https://docs.rs/static_assertions/1.1.0/static_assertions/macro.assert_eq_size.html\n[`assert_eq_size_ptr!`]:     https://docs.rs/static_assertions/1.1.0/static_assertions/macro.assert_eq_size_ptr.html\n[`assert_eq_size_val!`]:     https://docs.rs/static_assertions/1.1.0/static_assertions/macro.assert_eq_size_val.html\n[`assert_fields!`]:          https://docs.rs/static_assertions/1.1.0/static_assertions/macro.assert_fields.html\n[`assert_impl_all!`]:        https://docs.rs/static_assertions/1.1.0/static_assertions/macro.assert_impl_all.html\n[`assert_impl_any!`]:        https://docs.rs/static_assertions/1.1.0/static_assertions/macro.assert_impl_any.html\n[`assert_impl_one!`]:        https://docs.rs/static_assertions/1.1.0/static_assertions/macro.assert_impl_one.html\n[`assert_not_impl_all!`]:    https://docs.rs/static_assertions/1.1.0/static_assertions/macro.assert_not_impl_all.html\n[`assert_not_impl_any!`]:    https://docs.rs/static_assertions/1.1.0/static_assertions/macro.assert_not_impl_any.html\n[`assert_obj_safe!`]:        https://docs.rs/static_assertions/1.1.0/static_assertions/macro.assert_obj_safe.html\n[`assert_trait_sub_all!`]:   https://docs.rs/static_assertions/1.1.0/static_assertions/macro.assert_trait_sub_all.html\n[`assert_trait_super_all!`]: https://docs.rs/static_assertions/1.1.0/static_assertions/macro.assert_trait_super_all.html\n[`assert_type_eq_all!`]:     https://docs.rs/static_assertions/1.1.0/static_assertions/macro.assert_type_eq_all.html\n[`assert_type_ne_all!`]:     https://docs.rs/static_assertions/1.1.0/static_assertions/macro.assert_type_ne_all.html\n[`const_assert!`]:           https://docs.rs/static_assertions/1.1.0/static_assertions/macro.const_assert.html\n[`const_assert_eq!`]:        https://docs.rs/static_assertions/1.1.0/static_assertions/macro.const_assert_eq.html\n[`const_assert_ne!`]:        https://docs.rs/static_assertions/1.1.0/static_assertions/macro.const_assert_ne.html\n","funding_links":["https://github.com/sponsors/nvzqz","https://patreon.com/nvzqz","https://www.paypal.me/nvzqz","https://www.patreon.com/nvzqz"],"categories":["Rust"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnvzqz%2Fstatic-assertions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnvzqz%2Fstatic-assertions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnvzqz%2Fstatic-assertions/lists"}