1 //! [](https://github.com/nvzqz/static-assertions-rs) 2 //! 3 //! <div align="center"> 4 //! <a href="https://crates.io/crates/static_assertions"> 5 //! <img src="https://img.shields.io/crates/d/static_assertions.svg" alt="Downloads"> 6 //! </a> 7 //! <a href="https://github.com/nvzqz/static-assertions-rs/actions?query=workflow%3ACI"> 8 //! <img src="https://github.com/nvzqz/static-assertions-rs/workflows/CI/badge.svg" alt="Build Status"> 9 //! </a> 10 //! <img src="https://img.shields.io/badge/rustc-^1.37.0-blue.svg" alt="rustc ^1.37.0"> 11 //! <br><br> 12 //! </div> 13 //! 14 //! Assertions to ensure correct assumptions about constants, types, and more. 15 //! 16 //! _All_ checks provided by this crate are performed at [compile-time]. This 17 //! allows for finding errors quickly and early when it comes to ensuring 18 //! certain features or aspects of a codebase. These macros are especially 19 //! important when exposing a public API that requires types to be the same size 20 //! or implement certain traits. 21 //! 22 //! # Usage 23 //! 24 //! This crate is available [on crates.io][crate] and can be used by adding the 25 //! following to your project's [`Cargo.toml`]: 26 //! 27 //! ```toml 28 //! [dependencies] 29 //! static_assertions = "1.1.0" 30 //! ``` 31 //! 32 //! and this to your crate root (`main.rs` or `lib.rs`): 33 //! 34 //! ``` 35 //! # #[allow(unused_imports)] 36 //! #[macro_use] 37 //! extern crate static_assertions; 38 //! # fn main() {} 39 //! ``` 40 //! 41 //! When using [Rust 2018 edition][2018], the following shorthand can help if 42 //! having `#[macro_use]` is undesirable. 43 //! 44 //! ```edition2018 45 //! extern crate static_assertions as sa; 46 //! 47 //! sa::const_assert!(true); 48 //! ``` 49 //! 50 //! ## Procedural Extensions 51 //! 52 //! As an extension crate [`proc_static_assertions`] adds a number of new 53 //! assertions to this. These are implemented as [procedural macros], hence the 54 //! "proc" prefix. As a result, they have a bit more visibility over what's 55 //! being asserted over than normal macros would. 56 //! 57 //! It can be enabled via the `proc` feature flag in your [`Cargo.toml`]: 58 //! 59 //! ```toml 60 //! [dependencies] 61 //! static_assertions = { version = "1.1.0", features = ["proc"] } 62 //! ``` 63 //! 64 //! # Examples 65 //! 66 //! Very thorough examples are provided in the docs for 67 //! [each individual macro](#macros). Failure case examples are also documented. 68 //! 69 //! # Changes 70 //! 71 //! See [`CHANGELOG.md`](https://github.com/nvzqz/static-assertions-rs/blob/master/CHANGELOG.md) 72 //! for an exhaustive list of what has changed from one version to another. 73 //! 74 //! # Donate 75 //! 76 //! This project is made freely available (as in free beer), but unfortunately 77 //! not all beer is free! So, if you would like to buy me a beer (or coffee or 78 //! *more*), then consider supporting my work that's benefited your project 79 //! and thousands of others. 80 //! 81 //! <a href="https://www.patreon.com/nvzqz"> 82 //! <img src="https://c5.patreon.com/external/logo/become_a_patron_button.png" alt="Become a Patron!" height="35"> 83 //! </a> 84 //! <a href="https://www.paypal.me/nvzqz"> 85 //! <img src="https://buymecoffee.intm.org/img/button-paypal-white.png" alt="Buy me a coffee" height="35"> 86 //! </a> 87 //! 88 //! [`proc_static_assertions`]: https://docs.rs/proc_static_assertions 89 //! [procedural macros]: https://doc.rust-lang.org/book/ch19-06-macros.html#procedural-macros-for-generating-code-from-attributes 90 //! [Rust 1.37]: https://blog.rust-lang.org/2019/08/15/Rust-1.37.0.html 91 //! [2018]: https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html#rust-2018 92 //! [crate]: https://crates.io/crates/static_assertions 93 //! [compile-time]: https://en.wikipedia.org/wiki/Compile_time 94 //! [`Cargo.toml`]: https://doc.rust-lang.org/cargo/reference/manifest.html 95 96 #![deny(missing_docs, unused_macros)] 97 #![doc( 98 html_root_url = "https://docs.rs/static_assertions/1.1.0", 99 html_logo_url = "https://raw.githubusercontent.com/nvzqz/static-assertions-rs/assets/Icon.png", 100 test(attr(deny(warnings), allow(dead_code))) 101 )] 102 #![no_std] 103 104 #[cfg(android_dylib)] 105 extern crate std; 106 107 #[cfg(feature = "proc_static_assertions")] 108 extern crate proc_static_assertions; 109 #[cfg(feature = "proc_static_assertions")] 110 pub use proc_static_assertions::assert; 111 112 // This module should never be used publicly and is not part of this crate's 113 // semver requirements. 114 #[doc(hidden)] 115 pub extern crate core as _core; 116 117 mod assert_align; 118 mod assert_cfg; 119 mod assert_fields; 120 mod assert_impl; 121 mod assert_obj_safe; 122 mod assert_size; 123 mod assert_trait; 124 mod assert_type; 125 mod const_assert; 126 mod does_impl; 127 128 // Utility macros. 129 // 130 // These macros should also never be used publicly and are not part of this 131 // crate's semver requirements. 132 mod util; 133 134 // Type-level booleans. 135 // 136 // This module should never be used publicly and is not part of this crate's 137 // semver requirements. 138 #[doc(hidden)] 139 #[path = "bool.rs"] 140 pub mod _bool; 141 142 // These types should also never be used publicly and are not part of this 143 // crate's semver requirements. 144 #[doc(hidden)] 145 pub use _bool::{False, True}; 146