use crate::priv_prelude::*;
#[derive(Clone, Debug, Serialize)]
pub struct Annotated<T> {
pub attribute_list: Vec<AttributeDecl>,
pub value: T,
}
#[derive(Clone, Debug, Serialize)]
pub struct AttributeDecl {
pub hash_kind: AttributeHashKind,
pub attribute: SquareBrackets<Punctuated<Attribute, CommaToken>>,
}
impl Spanned for AttributeDecl {
fn span(&self) -> Span {
let hash_span = match &self.hash_kind {
AttributeHashKind::Inner(hash_bang_token) => hash_bang_token.span(),
AttributeHashKind::Outer(hash_token) => hash_token.span(),
};
Span::join(hash_span, &self.attribute.span())
}
}
#[derive(Clone, Debug, Serialize)]
pub enum AttributeHashKind {
Inner(HashBangToken),
Outer(HashToken),
}
#[derive(Clone, Debug, Serialize)]
pub struct AttributeArg {
pub name: Ident,
pub value: Option<Literal>,
}
impl Spanned for AttributeArg {
fn span(&self) -> Span {
if let Some(value) = &self.value {
Span::join(self.name.span(), &value.span())
} else {
self.name.span()
}
}
}
#[derive(Clone, Debug, Serialize)]
pub struct Attribute {
pub name: Ident,
pub args: Option<Parens<Punctuated<AttributeArg, CommaToken>>>,
}
impl Spanned for Attribute {
fn span(&self) -> Span {
self.args
.as_ref()
.map(|args| Span::join(self.name.span(), &args.span()))
.unwrap_or_else(|| self.name.span())
}
}