blob: 60bb4da1b64165e589e1f618b697cfce1911031d [file] [log] [blame]
David Tolnay7db73692019-10-20 14:51:12 -04001use proc_macro2::TokenStream;
2use quote::{quote, ToTokens};
3use syn::LitStr;
4
5pub struct Doc {
6 fragments: Vec<LitStr>,
7}
8
9impl Doc {
10 pub fn new() -> Self {
11 Doc {
12 fragments: Vec::new(),
13 }
14 }
15
16 pub fn push(&mut self, lit: LitStr) {
17 self.fragments.push(lit);
18 }
19
20 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
30impl ToTokens for Doc {
31 fn to_tokens(&self, tokens: &mut TokenStream) {
32 let fragments = &self.fragments;
33 tokens.extend(quote! {
34 #(#[doc = #fragments])*
35 });
36 }
37}