assert_impl_trait/lib.rs
1#![deny(missing_docs)]
2#![doc = include_str!("../README.md")]
3
4mod assert_impl;
5mod parse;
6mod token_iter;
7mod types;
8
9/// A simple macro for making compile-time assertions that a type implements a
10/// given trait.
11///
12/// This macro supports generic parameters via `for<...>` syntax and trait
13/// bounds via `where ...` syntax.
14///
15/// # Examples
16///
17/// ```
18/// use assert_impl_trait::assert_impl;
19///
20/// // Assert that `u8` implements `Clone`.
21/// assert_impl!(u8: Clone);
22///
23/// // Assert that for any type `T` that implements `Clone`, `Vec<T>` also
24/// // implements `Clone`.
25/// assert_impl!(
26/// for<T: Clone> {
27/// Vec<T>: Clone,
28/// }
29/// );
30///
31/// // Assert that for any type `T` and any integer `N`:
32/// // - If `T` implements `Clone`, `[T; N]` also implements `Clone`.
33/// // - If `T` implements `Copy`, `[T; N]` also implements `Copy`.
34/// // - If `T` is valid for a lifetime, `[T; N]` is also valid for it.
35/// assert_impl!(
36/// for<T, const N: usize> {
37/// where T: Clone {
38/// [T; N]: Clone,
39/// }
40/// where T: Copy {
41/// [T; N]: Copy,
42/// }
43///
44/// for<'a> where T: 'a {
45/// [T; N]: 'a,
46/// }
47/// }
48/// );
49///
50/// // Assert that `Debug` is a dyn-compatible trait.
51/// assert_impl!(dyn core::fmt::Debug:);
52/// ```
53#[proc_macro]
54pub fn assert_impl(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
55 assert_impl::main(input)
56}