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§
impl Copy for Spacing
impl Eq 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
)§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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 more