forked from anixe/doku
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.rs
48 lines (40 loc) · 1.19 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
mod attrs;
mod error;
mod expand;
mod utils;
mod prelude {
pub(crate) use super::{
attrs::{self, RenameRule},
error::*,
utils::*,
};
pub use proc_macro::TokenStream;
pub use proc_macro2::{Span, TokenStream as TokenStream2};
pub use quote::{quote, quote_spanned};
pub use syn::spanned::Spanned;
pub type Result<T, E = Error> = std::result::Result<T, E>;
}
use self::prelude::*;
use syn::parse_macro_input;
#[proc_macro_derive(Document, attributes(doku))]
pub fn derive_document(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as syn::DeriveInput);
match expand::expand(&input) {
Ok(stream) => stream,
Err(err) => {
let err = err.compile();
let ident = input.ident;
// We're emitting a dummy impl to avoid a potential error-cascade
// when something else already expects this type to be doku-fied
quote! {
#err
impl ::doku::Document for #ident {
fn ty() -> ::doku::Type {
unreachable!()
}
}
}
}
}
.into()
}