Expand description

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 };

Modules

Macros

  • A macro that makes it easier to generate assertions into an assertion store