proc_macro

Struct Ident

1.29.0 · Source
pub struct Ident(/* private fields */);
Expand description

An identifier (ident).

Implementations§

Source§

impl Ident

1.29.0 · Source

pub fn new(string: &str, span: Span) -> Ident

Creates a new Ident with the given string as well as the specified span. The string argument must be a valid identifier permitted by the language (including keywords, e.g. self or fn). Otherwise, the function will panic.

Note that span, currently in rustc, configures the hygiene information for this identifier.

As of this time Span::call_site() explicitly opts-in to “call-site” hygiene meaning that identifiers created with this span will be resolved as if they were written directly at the location of the macro call, and other code at the macro call site will be able to refer to them as well.

Later spans like Span::def_site() will allow to opt-in to “definition-site” hygiene meaning that identifiers created with this span will be resolved at the location of the macro definition and other code at the macro call site will not be able to refer to them.

Due to the current importance of hygiene this constructor, unlike other tokens, requires a Span to be specified at construction.

1.47.0 · Source

pub fn new_raw(string: &str, span: Span) -> Ident

Same as Ident::new, but creates a raw identifier (r#ident). The string argument be a valid identifier permitted by the language (including keywords, e.g. fn). Keywords which are usable in path segments (e.g. self, super) are not supported, and will cause a panic.

1.29.0 · Source

pub fn span(&self) -> Span

Returns the span of this Ident, encompassing the entire string returned by to_string.

1.29.0 · Source

pub fn set_span(&mut self, span: Span)

Configures the span of this Ident, possibly changing its hygiene context.

Trait Implementations§

1.29.0 · Source§

impl Clone for Ident

Source§

fn clone(&self) -> Ident

Returns a copy of the value. Read more
1.15.0 · Source§

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

Performs copy-assignment from source. Read more
1.29.0 · Source§

impl Debug for Ident

Source§

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

Formats the value using the given formatter. Read more
1.29.0 · Source§

impl Display for Ident

Prints the identifier as a string that should be losslessly convertible back into the same identifier.

Source§

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

Formats the value using the given formatter. Read more
1.29.0 · Source§

impl From<Ident> for TokenTree

Source§

fn from(g: Ident) -> TokenTree

Converts to this type from the input type.
Source§

impl ToTokens for Ident

Source§

fn to_tokens(&self, tokens: &mut TokenStream)

🔬This is a nightly-only experimental API. (proc_macro_totokens #130977)
Write self to the given TokenStream. Read more
Source§

fn to_token_stream(&self) -> TokenStream

🔬This is a nightly-only experimental API. (proc_macro_totokens #130977)
Convert self directly into a TokenStream object. Read more
Source§

fn into_token_stream(self) -> TokenStream
where Self: Sized,

🔬This is a nightly-only experimental API. (proc_macro_totokens #130977)
Convert self directly into a TokenStream object. Read more

Auto Trait Implementations§

§

impl Freeze for Ident

§

impl RefUnwindSafe for Ident

§

impl !Send for Ident

§

impl !Sync for Ident

§

impl Unpin for Ident

§

impl UnwindSafe for Ident

Blanket Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit #126799)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

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> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

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>,

Source§

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.