Struct rustc_ast::ast::Attribute

source ·
pub struct Attribute {
    pub kind: AttrKind,
    pub id: AttrId,
    pub style: AttrStyle,
    pub span: Span,
}
Expand description

A syntax-level representation of an attribute.

Fields§

§kind: AttrKind§id: AttrId§style: AttrStyle

Denotes if the attribute decorates the following construct (outer) or the construct this attribute is contained within (inner).

§span: Span

Implementations§

source§

impl Attribute

source

pub fn get_normal_item(&self) -> &AttrItem

source

pub fn unwrap_normal_item(self) -> AttrItem

source

pub fn is_doc_comment(&self) -> bool

Returns true if it is a sugared doc comment (/// or //! for example). So #[doc = "doc"] (which is a doc comment) and #[doc(...)] (which is not a doc comment) will return false.

source

pub fn ident(&self) -> Option<Ident>

For a single-segment attribute, returns its name; otherwise, returns None.

source

pub fn name_or_empty(&self) -> Symbol

source

pub fn has_name(&self, name: Symbol) -> bool

source

pub fn path_matches(&self, name: &[Symbol]) -> bool

source

pub fn is_word(&self) -> bool

source

pub fn meta_item_list(&self) -> Option<ThinVec<NestedMetaItem>>

source

pub fn value_str(&self) -> Option<Symbol>

source

pub fn doc_str_and_comment_kind(&self) -> Option<(Symbol, CommentKind)>

Returns the documentation and its kind if this is a doc comment or a sugared doc comment.

  • ///doc returns Some(("doc", CommentKind::Line)).
  • /** doc */ returns Some(("doc", CommentKind::Block)).
  • #[doc = "doc"] returns Some(("doc", CommentKind::Line)).
  • #[doc(...)] returns None.
source

pub fn doc_str(&self) -> Option<Symbol>

Returns the documentation if this is a doc comment or a sugared doc comment.

  • ///doc returns Some("doc").
  • #[doc = "doc"] returns Some("doc").
  • #[doc(...)] returns None.
source

pub fn is_proc_macro_attr(&self) -> bool

source

pub fn meta(&self) -> Option<MetaItem>

Extracts the MetaItem from inside this Attribute.

source

pub fn meta_kind(&self) -> Option<MetaItemKind>

source

pub fn tokens(&self) -> TokenStream

Trait Implementations§

source§

impl Clone for Attribute

source§

fn clone(&self) -> Attribute

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Attribute

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<__D: SpanDecoder> Decodable<__D> for Attribute

source§

fn decode(__decoder: &mut __D) -> Self

source§

impl<__E: SpanEncoder> Encodable<__E> for Attribute

source§

fn encode(&self, __encoder: &mut __E)

source§

impl HasAttrs for Attribute

source§

const SUPPORTS_CUSTOM_INNER_ATTRS: bool = false

This is true if this HasAttrs might support ‘custom’ (proc-macro) inner attributes. Attributes like #![cfg] and #![cfg_attr] are not considered ‘custom’ attributes. Read more
source§

fn attrs(&self) -> &[Attribute]

source§

fn visit_attrs(&mut self, _f: impl FnOnce(&mut AttrVec))

source§

impl HasTokens for Attribute

source§

impl<AstCtx: HashStableContext> HashStable<AstCtx> for Attribute

source§

fn hash_stable(&self, hcx: &mut AstCtx, hasher: &mut StableHasher)

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Aligned for T

source§

const ALIGN: Alignment = _

Alignment of Self.
source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<'a, T> Captures<'a> for T
where T: ?Sized,

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 32 bytes