mirror of
https://gitee.com/openharmony/third_party_rust_cxx
synced 2024-11-24 07:40:19 +00:00
38 lines
723 B
Rust
38 lines
723 B
Rust
use proc_macro2::TokenStream;
|
|
use quote::{quote, ToTokens};
|
|
use syn::LitStr;
|
|
|
|
pub struct Doc {
|
|
fragments: Vec<LitStr>,
|
|
}
|
|
|
|
impl Doc {
|
|
pub fn new() -> Self {
|
|
Doc {
|
|
fragments: Vec::new(),
|
|
}
|
|
}
|
|
|
|
pub fn push(&mut self, lit: LitStr) {
|
|
self.fragments.push(lit);
|
|
}
|
|
|
|
pub fn to_string(&self) -> String {
|
|
let mut doc = String::new();
|
|
for lit in &self.fragments {
|
|
doc += &lit.value();
|
|
doc.push('\n');
|
|
}
|
|
doc
|
|
}
|
|
}
|
|
|
|
impl ToTokens for Doc {
|
|
fn to_tokens(&self, tokens: &mut TokenStream) {
|
|
let fragments = &self.fragments;
|
|
tokens.extend(quote! {
|
|
#(#[doc = #fragments])*
|
|
});
|
|
}
|
|
}
|