proc_macro::Literal - Rust
Description: API documentation for the Rust `Literal` struct in crate `proc_macro`.
Keywords: rust, rustlang, rust-lang, Literal

# 1.29.0[−][src]Struct proc_macro::Literal

    pub struct Literal(_);

A literal string (`"hello"`), byte string (`b"hello"`), character (`'a'`), byte character (`b'a'`), an integer or floating point number with or without a suffix (`1`, `1u8`, `2.3`, `2.3f32`). Boolean literals like `true` and `false` do not belong here, they are `Ident`s.

## Methods

###

`impl Literal`

[src]

####

`pub fn u8_suffixed(n: u8) -> Literal`

[src]

Creates a new suffixed integer literal with the specified value.

This function will create an integer like `1u32` where the integer value specified is the first part of the token and the integral is also suffixed at the end. Literals created from negative numbers may not survive round-trips through `TokenStream` or strings and may be broken into two tokens (`-` and positive literal).

Literals created through this method have the `Span::call_site()` span by default, which can be configured with the `set_span` method below.

####

`pub fn u16_suffixed(n: u16) -> Literal`

[src]

Creates a new suffixed integer literal with the specified value.

This function will create an integer like `1u32` where the integer value specified is the first part of the token and the integral is also suffixed at the end. Literals created from negative numbers may not survive round-trips through `TokenStream` or strings and may be broken into two tokens (`-` and positive literal).

Literals created through this method have the `Span::call_site()` span by default, which can be configured with the `set_span` method below.

####

`pub fn u32_suffixed(n: u32) -> Literal`

[src]

Creates a new suffixed integer literal with the specified value.

This function will create an integer like `1u32` where the integer value specified is the first part of the token and the integral is also suffixed at the end. Literals created from negative numbers may not survive round-trips through `TokenStream` or strings and may be broken into two tokens (`-` and positive literal).

Literals created through this method have the `Span::call_site()` span by default, which can be configured with the `set_span` method below.

####

`pub fn u64_suffixed(n: u64) -> Literal`

[src]

Creates a new suffixed integer literal with the specified value.

This function will create an integer like `1u32` where the integer value specified is the first part of the token and the integral is also suffixed at the end. Literals created from negative numbers may not survive round-trips through `TokenStream` or strings and may be broken into two tokens (`-` and positive literal).

Literals created through this method have the `Span::call_site()` span by default, which can be configured with the `set_span` method below.

####

`pub fn u128_suffixed(n: u128) -> Literal`

[src]

Creates a new suffixed integer literal with the specified value.

This function will create an integer like `1u32` where the integer value specified is the first part of the token and the integral is also suffixed at the end. Literals created from negative numbers may not survive round-trips through `TokenStream` or strings and may be broken into two tokens (`-` and positive literal).

Literals created through this method have the `Span::call_site()` span by default, which can be configured with the `set_span` method below.

####

`pub fn usize_suffixed(n: usize) -> Literal`

[src]

Creates a new suffixed integer literal with the specified value.

This function will create an integer like `1u32` where the integer value specified is the first part of the token and the integral is also suffixed at the end. Literals created from negative numbers may not survive round-trips through `TokenStream` or strings and may be broken into two tokens (`-` and positive literal).

Literals created through this method have the `Span::call_site()` span by default, which can be configured with the `set_span` method below.

####

`pub fn i8_suffixed(n: i8) -> Literal`

[src]

Creates a new suffixed integer literal with the specified value.

This function will create an integer like `1u32` where the integer value specified is the first part of the token and the integral is also suffixed at the end. Literals created from negative numbers may not survive round-trips through `TokenStream` or strings and may be broken into two tokens (`-` and positive literal).

Literals created through this method have the `Span::call_site()` span by default, which can be configured with the `set_span` method below.

####

`pub fn i16_suffixed(n: i16) -> Literal`

[src]

Creates a new suffixed integer literal with the specified value.

This function will create an integer like `1u32` where the integer value specified is the first part of the token and the integral is also suffixed at the end. Literals created from negative numbers may not survive round-trips through `TokenStream` or strings and may be broken into two tokens (`-` and positive literal).

Literals created through this method have the `Span::call_site()` span by default, which can be configured with the `set_span` method below.

####

`pub fn i32_suffixed(n: i32) -> Literal`

[src]

Creates a new suffixed integer literal with the specified value.

This function will create an integer like `1u32` where the integer value specified is the first part of the token and the integral is also suffixed at the end. Literals created from negative numbers may not survive round-trips through `TokenStream` or strings and may be broken into two tokens (`-` and positive literal).

Literals created through this method have the `Span::call_site()` span by default, which can be configured with the `set_span` method below.

####

`pub fn i64_suffixed(n: i64) -> Literal`

[src]

Creates a new suffixed integer literal with the specified value.

This function will create an integer like `1u32` where the integer value specified is the first part of the token and the integral is also suffixed at the end. Literals created from negative numbers may not survive round-trips through `TokenStream` or strings and may be broken into two tokens (`-` and positive literal).

Literals created through this method have the `Span::call_site()` span by default, which can be configured with the `set_span` method below.

####

`pub fn i128_suffixed(n: i128) -> Literal`

[src]

Creates a new suffixed integer literal with the specified value.

This function will create an integer like `1u32` where the integer value specified is the first part of the token and the integral is also suffixed at the end. Literals created from negative numbers may not survive round-trips through `TokenStream` or strings and may be broken into two tokens (`-` and positive literal).

Literals created through this method have the `Span::call_site()` span by default, which can be configured with the `set_span` method below.

####

`pub fn isize_suffixed(n: isize) -> Literal`

[src]

Creates a new suffixed integer literal with the specified value.

This function will create an integer like `1u32` where the integer value specified is the first part of the token and the integral is also suffixed at the end. Literals created from negative numbers may not survive round-trips through `TokenStream` or strings and may be broken into two tokens (`-` and positive literal).

Literals created through this method have the `Span::call_site()` span by default, which can be configured with the `set_span` method below.

####

`pub fn u8_unsuffixed(n: u8) -> Literal`

[src]

Creates a new unsuffixed integer literal with the specified value.

This function will create an integer like `1` where the integer value specified is the first part of the token. No suffix is specified on this token, meaning that invocations like `Literal::i8_unsuffixed(1)` are equivalent to `Literal::u32_unsuffixed(1)`. Literals created from negative numbers may not survive rountrips through `TokenStream` or strings and may be broken into two tokens (`-` and positive literal).

Literals created through this method have the `Span::call_site()` span by default, which can be configured with the `set_span` method below.

####

`pub fn u16_unsuffixed(n: u16) -> Literal`

[src]

Creates a new unsuffixed integer literal with the specified value.

This function will create an integer like `1` where the integer value specified is the first part of the token. No suffix is specified on this token, meaning that invocations like `Literal::i8_unsuffixed(1)` are equivalent to `Literal::u32_unsuffixed(1)`. Literals created from negative numbers may not survive rountrips through `TokenStream` or strings and may be broken into two tokens (`-` and positive literal).

Literals created through this method have the `Span::call_site()` span by default, which can be configured with the `set_span` method below.

####

`pub fn u32_unsuffixed(n: u32) -> Literal`

[src]

Creates a new unsuffixed integer literal with the specified value.

This function will create an integer like `1` where the integer value specified is the first part of the token. No suffix is specified on this token, meaning that invocations like `Literal::i8_unsuffixed(1)` are equivalent to `Literal::u32_unsuffixed(1)`. Literals created from negative numbers may not survive rountrips through `TokenStream` or strings and may be broken into two tokens (`-` and positive literal).

Literals created through this method have the `Span::call_site()` span by default, which can be configured with the `set_span` method below.

####

`pub fn u64_unsuffixed(n: u64) -> Literal`

[src]

Creates a new unsuffixed integer literal with the specified value.

This function will create an integer like `1` where the integer value specified is the first part of the token. No suffix is specified on this token, meaning that invocations like `Literal::i8_unsuffixed(1)` are equivalent to `Literal::u32_unsuffixed(1)`. Literals created from negative numbers may not survive rountrips through `TokenStream` or strings and may be broken into two tokens (`-` and positive literal).

Literals created through this method have the `Span::call_site()` span by default, which can be configured with the `set_span` method below.

####

`pub fn u128_unsuffixed(n: u128) -> Literal`

[src]

Creates a new unsuffixed integer literal with the specified value.

This function will create an integer like `1` where the integer value specified is the first part of the token. No suffix is specified on this token, meaning that invocations like `Literal::i8_unsuffixed(1)` are equivalent to `Literal::u32_unsuffixed(1)`. Literals created from negative numbers may not survive rountrips through `TokenStream` or strings and may be broken into two tokens (`-` and positive literal).

Literals created through this method have the `Span::call_site()` span by default, which can be configured with the `set_span` method below.

####

`pub fn usize_unsuffixed(n: usize) -> Literal`

[src]

Creates a new unsuffixed integer literal with the specified value.

This function will create an integer like `1` where the integer value specified is the first part of the token. No suffix is specified on this token, meaning that invocations like `Literal::i8_unsuffixed(1)` are equivalent to `Literal::u32_unsuffixed(1)`. Literals created from negative numbers may not survive rountrips through `TokenStream` or strings and may be broken into two tokens (`-` and positive literal).

Literals created through this method have the `Span::call_site()` span by default, which can be configured with the `set_span` method below.

####

`pub fn i8_unsuffixed(n: i8) -> Literal`

[src]

Creates a new unsuffixed integer literal with the specified value.

This function will create an integer like `1` where the integer value specified is the first part of the token. No suffix is specified on this token, meaning that invocations like `Literal::i8_unsuffixed(1)` are equivalent to `Literal::u32_unsuffixed(1)`. Literals created from negative numbers may not survive rountrips through `TokenStream` or strings and may be broken into two tokens (`-` and positive literal).

Literals created through this method have the `Span::call_site()` span by default, which can be configured with the `set_span` method below.

####

`pub fn i16_unsuffixed(n: i16) -> Literal`

[src]

Creates a new unsuffixed integer literal with the specified value.

This function will create an integer like `1` where the integer value specified is the first part of the token. No suffix is specified on this token, meaning that invocations like `Literal::i8_unsuffixed(1)` are equivalent to `Literal::u32_unsuffixed(1)`. Literals created from negative numbers may not survive rountrips through `TokenStream` or strings and may be broken into two tokens (`-` and positive literal).

Literals created through this method have the `Span::call_site()` span by default, which can be configured with the `set_span` method below.

####

`pub fn i32_unsuffixed(n: i32) -> Literal`

[src]

Creates a new unsuffixed integer literal with the specified value.

This function will create an integer like `1` where the integer value specified is the first part of the token. No suffix is specified on this token, meaning that invocations like `Literal::i8_unsuffixed(1)` are equivalent to `Literal::u32_unsuffixed(1)`. Literals created from negative numbers may not survive rountrips through `TokenStream` or strings and may be broken into two tokens (`-` and positive literal).

Literals created through this method have the `Span::call_site()` span by default, which can be configured with the `set_span` method below.

####

`pub fn i64_unsuffixed(n: i64) -> Literal`

[src]

Creates a new unsuffixed integer literal with the specified value.

This function will create an integer like `1` where the integer value specified is the first part of the token. No suffix is specified on this token, meaning that invocations like `Literal::i8_unsuffixed(1)` are equivalent to `Literal::u32_unsuffixed(1)`. Literals created from negative numbers may not survive rountrips through `TokenStream` or strings and may be broken into two tokens (`-` and positive literal).

Literals created through this method have the `Span::call_site()` span by default, which can be configured with the `set_span` method below.

####

`pub fn i128_unsuffixed(n: i128) -> Literal`

[src]

Creates a new unsuffixed integer literal with the specified value.

This function will create an integer like `1` where the integer value specified is the first part of the token. No suffix is specified on this token, meaning that invocations like `Literal::i8_unsuffixed(1)` are equivalent to `Literal::u32_unsuffixed(1)`. Literals created from negative numbers may not survive rountrips through `TokenStream` or strings and may be broken into two tokens (`-` and positive literal).

Literals created through this method have the `Span::call_site()` span by default, which can be configured with the `set_span` method below.

####

`pub fn isize_unsuffixed(n: isize) -> Literal`

[src]

Creates a new unsuffixed integer literal with the specified value.

This function will create an integer like `1` where the integer value specified is the first part of the token. No suffix is specified on this token, meaning that invocations like `Literal::i8_unsuffixed(1)` are equivalent to `Literal::u32_unsuffixed(1)`. Literals created from negative numbers may not survive rountrips through `TokenStream` or strings and may be broken into two tokens (`-` and positive literal).

Literals created through this method have the `Span::call_site()` span by default, which can be configured with the `set_span` method below.

####

`pub fn f32_unsuffixed(n: f32) -> Literal`

[src]

Creates a new unsuffixed floating-point literal.

This constructor is similar to those like `Literal::i8_unsuffixed` where the float's value is emitted directly into the token but no suffix is used, so it may be inferred to be a `f64` later in the compiler. Literals created from negative numbers may not survive rountrips through `TokenStream` or strings and may be broken into two tokens (`-` and positive literal).

# Panics

This function requires that the specified float is finite, for example if it is infinity or NaN this function will panic.

####

`pub fn f32_suffixed(n: f32) -> Literal`

[src]

Creates a new suffixed floating-point literal.

This constructor will create a literal like `1.0f32` where the value specified is the preceding part of the token and `f32` is the suffix of the token. This token will always be inferred to be an `f32` in the compiler. Literals created from negative numbers may not survive rountrips through `TokenStream` or strings and may be broken into two tokens (`-` and positive literal).

# Panics

This function requires that the specified float is finite, for example if it is infinity or NaN this function will panic.

####

`pub fn f64_unsuffixed(n: f64) -> Literal`

[src]

Creates a new unsuffixed floating-point literal.

This constructor is similar to those like `Literal::i8_unsuffixed` where the float's value is emitted directly into the token but no suffix is used, so it may be inferred to be a `f64` later in the compiler. Literals created from negative numbers may not survive rountrips through `TokenStream` or strings and may be broken into two tokens (`-` and positive literal).

# Panics

This function requires that the specified float is finite, for example if it is infinity or NaN this function will panic.

####

`pub fn f64_suffixed(n: f64) -> Literal`

[src]

Creates a new suffixed floating-point literal.

This constructor will create a literal like `1.0f64` where the value specified is the preceding part of the token and `f64` is the suffix of the token. This token will always be inferred to be an `f64` in the compiler. Literals created from negative numbers may not survive rountrips through `TokenStream` or strings and may be broken into two tokens (`-` and positive literal).

# Panics

This function requires that the specified float is finite, for example if it is infinity or NaN this function will panic.

####

`pub fn string(string: &str) -> Literal`

[src]

String literal.

####

`pub fn character(ch: char) -> Literal`

[src]

Character literal.

####

`pub fn byte_string(bytes: &[u8]) -> Literal`

[src]

Byte string literal.

####

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

[src]

Returns the span encompassing this literal.

####

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

[src]

Configures the span associated for this literal.

####

`pub fn subspan<R: RangeBounds<usize>>(&self, range: R) -> Option<Span>`

[src]

🔬 This is a nightly-only experimental API. (`proc_macro_span` #54725)

Returns a `Span` that is a subset of `self.span()` containing only the source bytes in range `range`. Returns `None` if the would-be trimmed span is outside the bounds of `self`.

## Trait Implementations

###

`impl Clone for Literal`

[src]

####

`fn clone(&self) -> Literal`

[src]

Returns a copy of the value. Read more

####

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

1.0.0
[src]

Performs copy-assignment from `source`. Read more

###

`impl ToString for Literal`

1.15.0
[src]

####

`fn to_string(&self) -> String`

[src]

Converts the given value to a `String`. Read more

###

`impl From<Literal> for TokenTree`

[src]

####

`fn from(g: Literal) -> TokenTree`

[src]

Performs the conversion.

###

`impl Display for Literal`

[src]

Prints the literal as a string that should be losslessly convertible back into the same literal (except for possible rounding for floating point literals).

####

`fn fmt(&self, f: &mut Formatter) -> Result`

[src]

Formats the value using the given formatter. Read more

###

`impl Debug for Literal`

[src]

####

`fn fmt(&self, f: &mut Formatter) -> Result`

[src]

Formats the value using the given formatter. Read more

## Auto Trait Implementations

###

`impl !Send for Literal`

###

`impl !Sync for Literal`

## Blanket Implementations

###

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

[src]

#### `type Owned = T`

####

`fn to_owned(&self) -> T`

[src]

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

####

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

[src]

🔬 This is a nightly-only experimental API. (`toowned_clone_into` #41263)

recently added

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

###

`impl<T> ToString for T where T: Display + ?Sized,`

[src]

####

`fn to_string(&self) -> String`

[src]

Converts the given value to a `String`. Read more

###

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

[src]

####

`fn into(self) -> U`

[src]

Performs the conversion.

###

`impl<T> From for T`

[src]

####

`fn from(t: T) -> T`

[src]

Performs the conversion.

###

`impl<T, U> TryFrom for T where T: From<U>,`

[src]

#### `type Error = !`

🔬 This is a nightly-only experimental API. (`try_from` #33417)

The type returned in the event of a conversion error.

####

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

[src]

🔬 This is a nightly-only experimental API. (`try_from` #33417)

Performs the conversion.

###

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

[src]

####

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

[src]

Immutably borrows from an owned value. Read more

###

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

[src]

####

`fn get_type_id(&self) -> TypeId`

[src]

🔬 This is a nightly-only experimental API. (`get_type_id` #27745)

this method will likely be replaced by an associated static

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

###

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

[src]

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

🔬 This is a nightly-only experimental API. (`try_from` #33417)

The type returned in the event of a conversion error.

####

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

[src]

🔬 This is a nightly-only experimental API. (`try_from` #33417)

Performs the conversion.

###

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

[src]

####

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

[src]

Mutably borrows from an owned value. Read more

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g. `str,u8` or `String,struct:Vec,test`)