Skip to main content

rustdoc_copy_macro/
lib.rs

1//! Procedual macros for crate `rustdoc_copy`.
2//!
3//! *The author of this crate is not good at English.*
4//! *Forgive me if the document is hard to read.*
5
6mod custom;
7mod doc;
8mod msg;
9mod util;
10use proc_macro as pm;
11use proc_macro2::TokenStream;
12
13/// Share documentation comment as given name module.
14///
15/// # Examples
16///
17/// ```
18/// use rustdoc_copy::prelude::*;
19///
20/// /// My function.
21/// #[doc_share(doc)]
22/// pub fn my_func() {
23///     println("`my_func` is called.");
24/// }
25///
26/// #[doc = doc::all!()]
27/// pub fn my_func_alias() {
28///     my_func();
29/// }
30/// ```
31#[proc_macro_attribute]
32pub fn doc_share(attr: pm::TokenStream, body: pm::TokenStream) -> pm::TokenStream {
33    let attr = TokenStream::from(attr);
34    let body = TokenStream::from(body);
35    let ret = custom::DocShare::translate(attr, body);
36    pm::TokenStream::from(ret)
37}
38
39/// Include Markdown file as given name module.
40#[proc_macro]
41pub fn doc_file(input: pm::TokenStream) -> pm::TokenStream {
42    let input = TokenStream::from(input);
43    let ret = custom::DocFile::translate(input);
44    pm::TokenStream::from(ret)
45}