pub struct MetaItem {
pub unsafety: Safety,
pub path: Path,
pub kind: MetaItemKind,
pub span: Span,
}
Expand description
A semantic representation of a meta item. A meta item is a slightly restricted form of an attribute – it can only contain expressions in certain leaf positions, rather than arbitrary token streams – that is used for most built-in attributes.
E.g., #[test]
, #[derive(..)]
, #[rustfmt::skip]
or #[feature = "foo"]
.
Fields§
§unsafety: Safety
§path: Path
§kind: MetaItemKind
§span: Span
Implementations§
Source§impl MetaItem
impl MetaItem
Sourcepub fn ident(&self) -> Option<Ident>
pub fn ident(&self) -> Option<Ident>
For a single-segment meta item, returns its name; otherwise, returns None
.
pub fn name_or_empty(&self) -> Symbol
pub fn has_name(&self, name: Symbol) -> bool
pub fn is_word(&self) -> bool
pub fn meta_item_list(&self) -> Option<&[MetaItemInner]>
Sourcepub fn name_value_literal(&self) -> Option<&MetaItemLit>
pub fn name_value_literal(&self) -> Option<&MetaItemLit>
Example:
#[attribute(name = "value")]
^^^^^^^^^^^^^^
Sourcepub fn name_value_literal_span(&self) -> Option<Span>
pub fn name_value_literal_span(&self) -> Option<Span>
This is used in case you want the value span instead of the whole attribute. Example:
#[doc(alias = "foo")]
In here, it’ll return a span for "foo"
.
Sourcepub fn value_str(&self) -> Option<Symbol>
pub fn value_str(&self) -> Option<Symbol>
Returns the string value in:
#[attribute = "value"]
^^^^^^^
It returns None
in any other cases like:
#[attr("value")]
fn from_tokens(iter: &mut TokenStreamIter<'_>) -> Option<MetaItem>
Trait Implementations§
Source§impl<__D: SpanDecoder> Decodable<__D> for MetaItem
impl<__D: SpanDecoder> Decodable<__D> for MetaItem
Source§impl<__E: SpanEncoder> Encodable<__E> for MetaItem
impl<__E: SpanEncoder> Encodable<__E> for MetaItem
Source§impl<__CTX> HashStable<__CTX> for MetaItemwhere
__CTX: HashStableContext,
impl<__CTX> HashStable<__CTX> for MetaItemwhere
__CTX: HashStableContext,
fn hash_stable(&self, __hcx: &mut __CTX, __hasher: &mut StableHasher)
Auto Trait Implementations§
impl DynSend for MetaItem
impl DynSync for MetaItem
impl Freeze for MetaItem
impl !RefUnwindSafe for MetaItem
impl !Send for MetaItem
impl !Sync for MetaItem
impl Unpin for MetaItem
impl !UnwindSafe for MetaItem
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<'a, T> Captures<'a> for Twhere
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: 88 bytes