double_derive/lib.rs
1mod double_trait;
2mod dummies;
3mod dummy_impl;
4
5use syn::{Error, ItemTrait, parse_macro_input};
6
7/// Generates a "dummy" implementation for each method in a trait using `unimplemented!()`. The main
8/// use case is to greate specialized test doubles for implementing the trait without worrying the
9/// need to explicitly implement methods, which are not invoked by the test.
10///
11/// * Existing default implementations are respected and not overridden.
12/// * `async` methods are supported
13/// * Methods returning `impl` Traits are not supported, with the exception of `impl Future` and
14/// `impl Iterator`.
15/// * Dummy implements the trait
16#[proc_macro_attribute]
17pub fn dummies(
18 _attr: proc_macro::TokenStream,
19 item: proc_macro::TokenStream,
20) -> proc_macro::TokenStream {
21 // let double_name = parse_macro_input!(attr as Ident);
22 let item = parse_macro_input!(item as ItemTrait);
23
24 let output = dummies::expand(item).unwrap_or_else(Error::into_compile_error);
25
26 proc_macro::TokenStream::from(output)
27}