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

#165 in Procedural macros

Download history 13/week @ 2023-12-14 9/week @ 2023-12-21 91/week @ 2024-01-11 43/week @ 2024-01-25 153/week @ 2024-02-01 72/week @ 2024-02-08 43/week @ 2024-02-15 404/week @ 2024-02-22 209/week @ 2024-02-29 52/week @ 2024-03-07 78/week @ 2024-03-14 24/week @ 2024-03-21 22/week @ 2024-03-28

185 downloads per month

MIT/Apache

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.4–0.9MB
~20K SLoC