pub enum Arg {
Flag(Ident),
Expr(Ident, Expr),
List(Ident, Args),
Lit(Lit),
}Expand description
A single parsed attribute argument.
Represents one of four forms: a bare flag (skip), a key-value expression
(rename = "foo"), a nested list (serde(flatten)), or a standalone literal ("hello").
Variants§
Implementations§
Source§impl Arg
impl Arg
Sourcepub fn name(&self) -> Option<&Ident>
pub fn name(&self) -> Option<&Ident>
Returns the name of this argument, or None for standalone literals.
Sourcepub fn is_expr(&self) -> bool
pub fn is_expr(&self) -> bool
Returns true if this is a key-value expression (e.g. rename = "foo").
Sourcepub fn as_str(&self) -> String
pub fn as_str(&self) -> String
Extracts the string value. Panics if the value is not a string literal.
Sourcepub fn as_int<T: FromStr>(&self) -> T
pub fn as_int<T: FromStr>(&self) -> T
Parses the integer value. Panics if the value is not an integer literal.
Sourcepub fn as_float<T: FromStr>(&self) -> T
pub fn as_float<T: FromStr>(&self) -> T
Parses the float value. Panics if the value is not a float literal.
Sourcepub fn as_char(&self) -> char
pub fn as_char(&self) -> char
Extracts the char value. Panics if the value is not a char literal.
Sourcepub fn as_expr_lit(&self) -> Option<&Lit>
pub fn as_expr_lit(&self) -> Option<&Lit>
Returns the literal if this is a Lit or an Expr containing a literal.
Trait Implementations§
Source§impl ToTokens for Arg
impl ToTokens for Arg
Source§fn to_tokens(&self, tokens: &mut TokenStream)
fn to_tokens(&self, tokens: &mut TokenStream)
Source§fn to_token_stream(&self) -> TokenStream
fn to_token_stream(&self) -> TokenStream
Source§fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
Auto Trait Implementations§
impl Freeze for Arg
impl RefUnwindSafe for Arg
impl !Send for Arg
impl !Sync for Arg
impl Unpin for Arg
impl UnsafeUnpin for Arg
impl UnwindSafe for Arg
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Spanned for Twhere
T: Spanned + ?Sized,
impl<T> Spanned for Twhere
T: Spanned + ?Sized,
Source§fn span(&self) -> Span
fn span(&self) -> Span
Returns a
Span covering the complete contents of this syntax tree
node, or Span::call_site() if this node is empty.