use quote::ToTokens;
use syn::{
parse::{Parse, ParseStream},
Attribute, Expr, Token,
};
pub struct DocComment(pub Expr);
impl DocComment {
pub fn from_attributes(attributes: &[Attribute]) -> syn::Result<Vec<Self>> {
attributes
.iter()
.filter(|attr| attr.path.is_ident("doc"))
.map(|attr| attr.tokens.clone())
.map(syn::parse2::<Self>)
.collect()
}
}
impl Parse for DocComment {
fn parse(input: ParseStream) -> syn::Result<Self> {
input.parse::<Token![=]>()?;
Ok(Self(input.parse()?))
}
}
impl ToTokens for DocComment {
fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
self.0.to_tokens(tokens);
}
}