Movatterモバイル変換


[0]ホーム

URL:


Literal

proc_macro

StructLiteral 

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 numberwith or without a suffix (1,1u8,2.3,2.3f32).Boolean literals liketrue andfalse do not belong here, they areIdents.

Implementations§

Source§

implLiteral

1.29.0 ·Source

pub fnu8_suffixed(n:u8) ->Literal

Creates a new suffixed integer literal with the specified value.

This function will create an integer like1u32 where the integervalue specified is the first part of the token and the integral isalso 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 theSpan::call_site()span by default, which can be configured with theset_span methodbelow.

1.29.0 ·Source

pub fnu16_suffixed(n:u16) ->Literal

Creates a new suffixed integer literal with the specified value.

This function will create an integer like1u32 where the integervalue specified is the first part of the token and the integral isalso 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 theSpan::call_site()span by default, which can be configured with theset_span methodbelow.

1.29.0 ·Source

pub fnu32_suffixed(n:u32) ->Literal

Creates a new suffixed integer literal with the specified value.

This function will create an integer like1u32 where the integervalue specified is the first part of the token and the integral isalso 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 theSpan::call_site()span by default, which can be configured with theset_span methodbelow.

1.29.0 ·Source

pub fnu64_suffixed(n:u64) ->Literal

Creates a new suffixed integer literal with the specified value.

This function will create an integer like1u32 where the integervalue specified is the first part of the token and the integral isalso 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 theSpan::call_site()span by default, which can be configured with theset_span methodbelow.

1.29.0 ·Source

pub fnu128_suffixed(n:u128) ->Literal

Creates a new suffixed integer literal with the specified value.

This function will create an integer like1u32 where the integervalue specified is the first part of the token and the integral isalso 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 theSpan::call_site()span by default, which can be configured with theset_span methodbelow.

1.29.0 ·Source

pub fnusize_suffixed(n:usize) ->Literal

Creates a new suffixed integer literal with the specified value.

This function will create an integer like1u32 where the integervalue specified is the first part of the token and the integral isalso 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 theSpan::call_site()span by default, which can be configured with theset_span methodbelow.

1.29.0 ·Source

pub fni8_suffixed(n:i8) ->Literal

Creates a new suffixed integer literal with the specified value.

This function will create an integer like1u32 where the integervalue specified is the first part of the token and the integral isalso 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 theSpan::call_site()span by default, which can be configured with theset_span methodbelow.

1.29.0 ·Source

pub fni16_suffixed(n:i16) ->Literal

Creates a new suffixed integer literal with the specified value.

This function will create an integer like1u32 where the integervalue specified is the first part of the token and the integral isalso 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 theSpan::call_site()span by default, which can be configured with theset_span methodbelow.

1.29.0 ·Source

pub fni32_suffixed(n:i32) ->Literal

Creates a new suffixed integer literal with the specified value.

This function will create an integer like1u32 where the integervalue specified is the first part of the token and the integral isalso 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 theSpan::call_site()span by default, which can be configured with theset_span methodbelow.

1.29.0 ·Source

pub fni64_suffixed(n:i64) ->Literal

Creates a new suffixed integer literal with the specified value.

This function will create an integer like1u32 where the integervalue specified is the first part of the token and the integral isalso 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 theSpan::call_site()span by default, which can be configured with theset_span methodbelow.

1.29.0 ·Source

pub fni128_suffixed(n:i128) ->Literal

Creates a new suffixed integer literal with the specified value.

This function will create an integer like1u32 where the integervalue specified is the first part of the token and the integral isalso 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 theSpan::call_site()span by default, which can be configured with theset_span methodbelow.

1.29.0 ·Source

pub fnisize_suffixed(n:isize) ->Literal

Creates a new suffixed integer literal with the specified value.

This function will create an integer like1u32 where the integervalue specified is the first part of the token and the integral isalso 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 theSpan::call_site()span by default, which can be configured with theset_span methodbelow.

1.29.0 ·Source

pub fnu8_unsuffixed(n:u8) ->Literal

Creates a new unsuffixed integer literal with the specified value.

This function will create an integer like1 where the integervalue specified is the first part of the token. No suffix isspecified 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 theSpan::call_site()span by default, which can be configured with theset_span methodbelow.

1.29.0 ·Source

pub fnu16_unsuffixed(n:u16) ->Literal

Creates a new unsuffixed integer literal with the specified value.

This function will create an integer like1 where the integervalue specified is the first part of the token. No suffix isspecified 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 theSpan::call_site()span by default, which can be configured with theset_span methodbelow.

1.29.0 ·Source

pub fnu32_unsuffixed(n:u32) ->Literal

Creates a new unsuffixed integer literal with the specified value.

This function will create an integer like1 where the integervalue specified is the first part of the token. No suffix isspecified 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 theSpan::call_site()span by default, which can be configured with theset_span methodbelow.

1.29.0 ·Source

pub fnu64_unsuffixed(n:u64) ->Literal

Creates a new unsuffixed integer literal with the specified value.

This function will create an integer like1 where the integervalue specified is the first part of the token. No suffix isspecified 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 theSpan::call_site()span by default, which can be configured with theset_span methodbelow.

1.29.0 ·Source

pub fnu128_unsuffixed(n:u128) ->Literal

Creates a new unsuffixed integer literal with the specified value.

This function will create an integer like1 where the integervalue specified is the first part of the token. No suffix isspecified 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 theSpan::call_site()span by default, which can be configured with theset_span methodbelow.

1.29.0 ·Source

pub fnusize_unsuffixed(n:usize) ->Literal

Creates a new unsuffixed integer literal with the specified value.

This function will create an integer like1 where the integervalue specified is the first part of the token. No suffix isspecified 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 theSpan::call_site()span by default, which can be configured with theset_span methodbelow.

1.29.0 ·Source

pub fni8_unsuffixed(n:i8) ->Literal

Creates a new unsuffixed integer literal with the specified value.

This function will create an integer like1 where the integervalue specified is the first part of the token. No suffix isspecified 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 theSpan::call_site()span by default, which can be configured with theset_span methodbelow.

1.29.0 ·Source

pub fni16_unsuffixed(n:i16) ->Literal

Creates a new unsuffixed integer literal with the specified value.

This function will create an integer like1 where the integervalue specified is the first part of the token. No suffix isspecified 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 theSpan::call_site()span by default, which can be configured with theset_span methodbelow.

1.29.0 ·Source

pub fni32_unsuffixed(n:i32) ->Literal

Creates a new unsuffixed integer literal with the specified value.

This function will create an integer like1 where the integervalue specified is the first part of the token. No suffix isspecified 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 theSpan::call_site()span by default, which can be configured with theset_span methodbelow.

1.29.0 ·Source

pub fni64_unsuffixed(n:i64) ->Literal

Creates a new unsuffixed integer literal with the specified value.

This function will create an integer like1 where the integervalue specified is the first part of the token. No suffix isspecified 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 theSpan::call_site()span by default, which can be configured with theset_span methodbelow.

1.29.0 ·Source

pub fni128_unsuffixed(n:i128) ->Literal

Creates a new unsuffixed integer literal with the specified value.

This function will create an integer like1 where the integervalue specified is the first part of the token. No suffix isspecified 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 theSpan::call_site()span by default, which can be configured with theset_span methodbelow.

1.29.0 ·Source

pub fnisize_unsuffixed(n:isize) ->Literal

Creates a new unsuffixed integer literal with the specified value.

This function will create an integer like1 where the integervalue specified is the first part of the token. No suffix isspecified 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 theSpan::call_site()span by default, which can be configured with theset_span methodbelow.

1.29.0 ·Source

pub fnf32_unsuffixed(n:f32) ->Literal

Creates a new unsuffixed floating-point literal.

This constructor is similar to those likeLiteral::i8_unsuffixed wherethe float’s value is emitted directly into the token but no suffix isused, so it may be inferred to be af64 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, forexample if it is infinity or NaN this function will panic.

1.29.0 ·Source

pub fnf32_suffixed(n:f32) ->Literal

Creates a new suffixed floating-point literal.

This constructor will create a literal like1.0f32 where the valuespecified is the preceding part of the token andf32 is the suffix ofthe token. This token will always be inferred to be anf32 in thecompiler.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, forexample if it is infinity or NaN this function will panic.

1.29.0 ·Source

pub fnf64_unsuffixed(n:f64) ->Literal

Creates a new unsuffixed floating-point literal.

This constructor is similar to those likeLiteral::i8_unsuffixed wherethe float’s value is emitted directly into the token but no suffix isused, so it may be inferred to be af64 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, forexample if it is infinity or NaN this function will panic.

1.29.0 ·Source

pub fnf64_suffixed(n:f64) ->Literal

Creates a new suffixed floating-point literal.

This constructor will create a literal like1.0f64 where the valuespecified is the preceding part of the token andf64 is the suffix ofthe token. This token will always be inferred to be anf64 in thecompiler.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, forexample if it is infinity or NaN this function will panic.

1.29.0 ·Source

pub fnstring(string: &str) ->Literal

String literal.

1.29.0 ·Source

pub fncharacter(ch:char) ->Literal

Character literal.

1.79.0 ·Source

pub fnbyte_character(byte:u8) ->Literal

Byte character literal.

1.29.0 ·Source

pub fnbyte_string(bytes: &[u8]) ->Literal

Byte string literal.

1.79.0 ·Source

pub fnc_string(string: &CStr) ->Literal

C string literal.

1.29.0 ·Source

pub fnspan(&self) ->Span

Returns the span encompassing this literal.

1.29.0 ·Source

pub fnset_span(&mut self, span:Span)

Configures the span associated for this literal.

Source

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

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

Returns aSpan that is a subset ofself.span() containing only thesource bytes in rangerange. ReturnsNone if the would-be trimmedspan is outside the bounds ofself.

Source

pub fnstr_value(&self) ->Result<String,ConversionErrorKind>

🔬This is a nightly-only experimental API. (proc_macro_value #136652)

Returns the unescaped string value if the current literal is a string or a string literal.

Source

pub fncstr_value(&self) ->Result<Vec<u8>,ConversionErrorKind>

🔬This is a nightly-only experimental API. (proc_macro_value #136652)

Returns the unescaped string value if the current literal is a c-string or a c-stringliteral.

Source

pub fnbyte_str_value(&self) ->Result<Vec<u8>,ConversionErrorKind>

🔬This is a nightly-only experimental API. (proc_macro_value #136652)

Returns the unescaped string value if the current literal is a byte string or a byte stringliteral.

Trait Implementations§

1.29.0 ·Source§

implClone forLiteral

Source§

fnclone(&self) ->Literal

Returns a duplicate of the value.Read more
1.0.0 ·Source§

fnclone_from(&mut self, source: &Self)

Performs copy-assignment fromsource.Read more
1.29.0 ·Source§

implDebug forLiteral

Source§

fnfmt(&self, f: &mutFormatter<'_>) ->Result

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

implDisplay forLiteral

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

Source§

fnfmt(&self, f: &mutFormatter<'_>) ->Result

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

implFrom<Literal> forTokenTree

Source§

fnfrom(g:Literal) ->TokenTree

Converts to this type from the input type.
1.54.0 ·Source§

implFromStr forLiteral

Parse a single literal from its stringified representation.

In order to parse successfully, the input string must not contain anythingbut the literal token. Specifically, it must not contain whitespace orcomments in addition to the literal.

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

NOTE: some errors may cause panics instead of returningLexError. Wereserve the right to change these errors intoLexErrors later.

Source§

typeErr =LexError

The associated error which can be returned from parsing.
Source§

fnfrom_str(src: &str) ->Result<Self,LexError>

Parses a strings to return a value of this type.Read more
Source§

implToTokens forLiteral

Source§

fnto_tokens(&self, tokens: &mutTokenStream)

🔬This is a nightly-only experimental API. (proc_macro_totokens #130977)
Writeself to the givenTokenStream.Read more
Source§

fnto_token_stream(&self) ->TokenStream

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

fninto_token_stream(self) ->TokenStream
where Self:Sized,

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

Auto Trait Implementations§

§

implFreeze forLiteral

§

implRefUnwindSafe forLiteral

§

impl !Send forLiteral

§

impl !Sync forLiteral

§

implUnpin forLiteral

§

implUnwindSafe forLiteral

Blanket Implementations§

Source§

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

Source§

fntype_id(&self) ->TypeId

Gets theTypeId ofself.Read more
Source§

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

Source§

fnborrow(&self) ->&T

Immutably borrows from an owned value.Read more
Source§

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

Source§

fnborrow_mut(&mut self) ->&mut T

Mutably borrows from an owned value.Read more
Source§

impl<T>CloneToUninit for T
where T:Clone,

Source§

unsafe fnclone_to_uninit(&self, dest:*mutu8)

🔬This is a nightly-only experimental API. (clone_to_uninit #126799)
Performs copy-assignment fromself todest.Read more
Source§

impl<T>From<T> for T

Source§

fnfrom(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fninto(self) -> U

CallsU::from(self).

That is, this conversion is whatever the implementation ofFrom<T> for U chooses to do.

Source§

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

Source§

typeOwned = T

The resulting type after obtaining ownership.
Source§

fnto_owned(&self) -> T

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

fnclone_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§

fnto_string(&self) ->String

Converts the given value to aString.Read more
Source§

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

Source§

typeError =Infallible

The type returned in the event of a conversion error.
Source§

fntry_from(value: U) ->Result<T, <T asTryFrom<U>>::Error>

Performs the conversion.
Source§

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

Source§

typeError = <U asTryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fntry_into(self) ->Result<U, <U asTryFrom<T>>::Error>

Performs the conversion.

[8]ページ先頭

©2009-2025 Movatter.jp