• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use proc_macro2::TokenStream;
2 use quote::{quote, ToTokens};
3 use syn::LitStr;
4 
5 pub struct Doc {
6     fragments: Vec<LitStr>,
7 }
8 
9 impl Doc {
new() -> Self10     pub fn new() -> Self {
11         Doc {
12             fragments: Vec::new(),
13         }
14     }
15 
push(&mut self, lit: LitStr)16     pub fn push(&mut self, lit: LitStr) {
17         self.fragments.push(lit);
18     }
19 
to_string(&self) -> String20     pub fn to_string(&self) -> String {
21         let mut doc = String::new();
22         for lit in &self.fragments {
23             doc += &lit.value();
24             doc.push('\n');
25         }
26         doc
27     }
28 }
29 
30 impl ToTokens for Doc {
to_tokens(&self, tokens: &mut TokenStream)31     fn to_tokens(&self, tokens: &mut TokenStream) {
32         let fragments = &self.fragments;
33         tokens.extend(quote! {
34             #(#[doc = #fragments])*
35         });
36     }
37 }
38