pub enum Spacing {
Alone,
Joint,
JointHidden,
}
Expand description
Indicates whether a token can join with the following token to form a
compound token. Used for conversions to proc_macro::Spacing
. Also used to
guide pretty-printing, which is where the JointHidden
value (which isn’t
part of proc_macro::Spacing
) comes in useful.
Variants§
Alone
The token cannot join with the following token to form a compound token.
In token streams parsed from source code, the compiler will use Alone
for any token immediately followed by whitespace, a non-doc comment, or
EOF.
When constructing token streams within the compiler, use this for each
token that (a) should be pretty-printed with a space after it, or (b)
is the last token in the stream. (In the latter case the choice of
spacing doesn’t matter because it is never used for the last token. We
arbitrarily use Alone
.)
Converts to proc_macro::Spacing::Alone
, and
proc_macro::Spacing::Alone
converts back to this.
Joint
The token can join with the following token to form a compound token.
In token streams parsed from source code, the compiler will use Joint
for any token immediately followed by punctuation (as determined by
Token::is_punct
).
When constructing token streams within the compiler, use this for each token that (a) should be pretty-printed without a space after it, and (b) is followed by a punctuation token.
Converts to proc_macro::Spacing::Joint
, and
proc_macro::Spacing::Joint
converts back to this.
JointHidden
The token can join with the following token to form a compound token,
but this will not be visible at the proc macro level. (This is what the
Hidden
means; see below.)
In token streams parsed from source code, the compiler will use
JointHidden
for any token immediately followed by anything not
covered by the Alone
and Joint
cases: an identifier, lifetime,
literal, delimiter, doc comment.
When constructing token streams, use this for each token that (a) should be pretty-printed without a space after it, and (b) is followed by a non-punctuation token.
Converts to proc_macro::Spacing::Alone
, but
proc_macro::Spacing::Alone
converts back to token::Spacing::Alone
.
Because of that, pretty-printing of TokenStream
s produced by proc
macros is unavoidably uglier (with more whitespace between tokens) than
pretty-printing of TokenStream
’s produced by other means (i.e. parsed
source code, internally constructed token streams, and token streams
produced by declarative macros).
Trait Implementations§
source§impl<__D: SpanDecoder> Decodable<__D> for Spacing
impl<__D: SpanDecoder> Decodable<__D> for Spacing
source§impl<__E: SpanEncoder> Encodable<__E> for Spacing
impl<__E: SpanEncoder> Encodable<__E> for Spacing
source§impl<__CTX> HashStable<__CTX> for Spacingwhere
__CTX: HashStableContext,
impl<__CTX> HashStable<__CTX> for Spacingwhere
__CTX: HashStableContext,
fn hash_stable(&self, __hcx: &mut __CTX, __hasher: &mut StableHasher)
impl Copy for Spacing
impl StructuralPartialEq for Spacing
Auto Trait Implementations§
impl Freeze for Spacing
impl RefUnwindSafe for Spacing
impl Send for Spacing
impl Sync for Spacing
impl Unpin for Spacing
impl UnwindSafe for Spacing
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<'a, T> Captures<'a> for Twhere
T: ?Sized,
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 1 byte
Size for each variant:
Alone
: 0 bytesJoint
: 0 bytesJointHidden
: 0 bytes