Literal in proc_macro - Rust (original) (raw)

Struct Literal

1.29.0 · Source

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

Expand description

A literal string ("hello"), byte string (b"hello"), C string (c"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 Idents.

Source§

1.29.0 · Source

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 might not survive round-trips throughTokenStream 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.

1.29.0 · Source

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 might not survive round-trips throughTokenStream 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.

1.29.0 · Source

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 might not survive round-trips throughTokenStream 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.

1.29.0 · Source

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 might not survive round-trips throughTokenStream 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.

1.29.0 · Source

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 might not survive round-trips throughTokenStream 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.

1.29.0 · Source

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 might not survive round-trips throughTokenStream 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.

1.29.0 · Source

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 might not survive round-trips throughTokenStream 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.

1.29.0 · Source

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 might not survive round-trips throughTokenStream 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.

1.29.0 · Source

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 might not survive round-trips throughTokenStream 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.

1.29.0 · Source

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 might not survive round-trips throughTokenStream 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.

1.29.0 · Source

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 might not survive round-trips throughTokenStream 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.

1.29.0 · Source

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 might not survive round-trips throughTokenStream 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.

1.29.0 · Source

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 likeLiteral::i8_unsuffixed(1) are equivalent toLiteral::u32_unsuffixed(1). Literals created from negative numbers might not survive rountrips throughTokenStream 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.

1.29.0 · Source

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 likeLiteral::i8_unsuffixed(1) are equivalent toLiteral::u32_unsuffixed(1). Literals created from negative numbers might not survive rountrips throughTokenStream 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.

1.29.0 · Source

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 likeLiteral::i8_unsuffixed(1) are equivalent toLiteral::u32_unsuffixed(1). Literals created from negative numbers might not survive rountrips throughTokenStream 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.

1.29.0 · Source

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 likeLiteral::i8_unsuffixed(1) are equivalent toLiteral::u32_unsuffixed(1). Literals created from negative numbers might not survive rountrips throughTokenStream 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.

1.29.0 · Source

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 likeLiteral::i8_unsuffixed(1) are equivalent toLiteral::u32_unsuffixed(1). Literals created from negative numbers might not survive rountrips throughTokenStream 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.

1.29.0 · Source

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 likeLiteral::i8_unsuffixed(1) are equivalent toLiteral::u32_unsuffixed(1). Literals created from negative numbers might not survive rountrips throughTokenStream 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.

1.29.0 · Source

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 likeLiteral::i8_unsuffixed(1) are equivalent toLiteral::u32_unsuffixed(1). Literals created from negative numbers might not survive rountrips throughTokenStream 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.

1.29.0 · Source

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 likeLiteral::i8_unsuffixed(1) are equivalent toLiteral::u32_unsuffixed(1). Literals created from negative numbers might not survive rountrips throughTokenStream 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.

1.29.0 · Source

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 likeLiteral::i8_unsuffixed(1) are equivalent toLiteral::u32_unsuffixed(1). Literals created from negative numbers might not survive rountrips throughTokenStream 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.

1.29.0 · Source

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 likeLiteral::i8_unsuffixed(1) are equivalent toLiteral::u32_unsuffixed(1). Literals created from negative numbers might not survive rountrips throughTokenStream 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.

1.29.0 · Source

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 likeLiteral::i8_unsuffixed(1) are equivalent toLiteral::u32_unsuffixed(1). Literals created from negative numbers might not survive rountrips throughTokenStream 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.

1.29.0 · Source

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 likeLiteral::i8_unsuffixed(1) are equivalent toLiteral::u32_unsuffixed(1). Literals created from negative numbers might not survive rountrips throughTokenStream 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.

1.29.0 · Source

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 might not survive rountrips throughTokenStream 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.

1.29.0 · Source

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 might not survive rountrips throughTokenStream 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.

1.29.0 · Source

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 might not survive rountrips throughTokenStream 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.

1.29.0 · Source

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 might not survive rountrips throughTokenStream 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.

1.29.0 · Source

String literal.

1.29.0 · Source

Character literal.

1.79.0 · Source

Byte character literal.

1.29.0 · Source

Byte string literal.

1.79.0 · Source

C string literal.

1.29.0 · Source

Returns the span encompassing this literal.

1.29.0 · Source

Configures the span associated for this literal.

Source

🔬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.

1.29.0 · Source§

1.29.0 · Source§

1.29.0 · Source§

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

1.29.0 · Source§

Source§

Converts to this type from the input type.

1.54.0 · Source§

Parse a single literal from its stringified representation.

In order to parse successfully, the input string must not contain anything but the literal token. Specifically, it must not contain whitespace or comments in addition to the literal.

The resulting literal token will have a Span::call_site() span.

NOTE: some errors may cause panics instead of returning LexError. We reserve the right to change these errors into LexErrors later.

Source§

The associated error which can be returned from parsing.

Source§

Parses a string s to return a value of this type. Read more

Source§

Source§

🔬This is a nightly-only experimental API. (proc_macro_totokens #130977)

Write self to the given TokenStream. Read more

Source§

🔬This is a nightly-only experimental API. (proc_macro_totokens #130977)

Convert self directly into a TokenStream object. Read more

Source§

🔬This is a nightly-only experimental API. (proc_macro_totokens #130977)

Convert self directly into a TokenStream object. Read more

§

§

§

§

§

§