use std::fmt::{Display, Formatter};
use proc_macro2::TokenStream;
use quote::{quote, ToTokens};
use syn::Attribute;
#[derive(Clone, Debug, Default)]
pub struct AttrWrapper {
pub attrs: Vec<Attribute>
}
impl AttrWrapper {
pub fn wrap<T: ToTokens>(&self, tokens: T) -> T {
match self.attrs.len() {
0 => tokens,
1 => {
tokens
}
_ => tokens
}
}
}
impl ToTokens for AttrWrapper {
fn to_tokens(&self, _tokens: &mut TokenStream) {
}
}
impl Display for AttrWrapper {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let attrs = &self.attrs;
f.write_fmt(format_args!("AttrWrapper({})", quote!(#(#attrs)*)))
}
}
impl From<Vec<Attribute>> for AttrWrapper {
fn from(attrs: Vec<Attribute>) -> Self {
AttrWrapper { attrs }
}
}
impl From<&Vec<Attribute>> for AttrWrapper {
fn from(attrs: &Vec<Attribute>) -> Self {
AttrWrapper { attrs: attrs.clone() }
}
}