13 releases
0.1.5 | Oct 11, 2023 |
---|---|
0.1.4 | Oct 11, 2023 |
0.0.7 | Oct 10, 2023 |
0.0.4 | Sep 17, 2023 |
0.0.2 | Aug 5, 2023 |
#283 in Procedural macros
36 downloads per month
91KB
2.5K
SLoC
This crate makes it easy to check inputs of proc macros for some conditions. It works by generating const code which is never actually executed but the type checking of it ensures the conditions are met.
For more information see the Static Assertions crate. (Disclaimer: I am not affiliated with the author of that crate in any way)
The core type of this crate is the Assertion Store
, which contains all the asserts that are
generated and then later turned into tokens.
For the included types of assertions it's recommended to use the assert_into!
macro.
The documentation of the individual items in this crate is pretty ok-ish, a funtional overview on how it works will be provided once I've got the time to draw that up. So for now just take a look at the individual types.
Example
pub use proc_macro_assertions::prelude::*;
let type_to_test: syn::Type = syn::parse_quote!(String);
let store = DefaultStore::new();
assert_into!(store | &type_to_test impl std::default::Default);
assert_into!(store | &type_to_test == String);
let tokens = quote::quote!{ #store };
Dependencies
~0.3–0.8MB
~18K SLoC