# Struct proc_macro::Ident

1.29.0 · source ·

    pub struct Ident(/* private fields */);

Expand description

An identifier (`ident`).

## Implementations§

source§

### impl Ident

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.

source

#### pub fn span(&self) -> Span

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

source

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

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

## Trait Implementations§

source§

### impl Clone for Ident

source§

#### fn clone(&self) -> Ident

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 Ident

source§

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

Formats the value using the given formatter. Read more
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
source§

### impl From<Ident> for TokenTree

source§

#### fn from(g: Ident) -> TokenTree

Converts to this type from the input type.

## Auto Trait Implementations§

§

### 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 Twhere T: 'static + ?Sized,

source§

#### fn type_id(&self) -> TypeId

Gets the `TypeId` of `self`. Read more
source§

### impl<T> Borrow<T> for Twhere T: ?Sized,

source§

#### fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

### impl<T> BorrowMut<T> for Twhere 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, U> Into<U> for Twhere 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 Twhere 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> ToString for Twhere 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 Twhere 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 Twhere 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.