pub struct AttachedToken(pub TokenWithSpan);Expand description
A wrapper over TokenWithSpans that ignores the token and source
location in comparisons and hashing.
This type is used when the token and location is not relevant for semantics, but is still needed for accurate source location tracking, for example, in the nodes in the ast module.
Note: All AttachedTokens are equal.
ยงExamples
Same token, different location are equal
// commas @ line 1, column 10
let tok1 = TokenWithLocation::new(
Token::Comma,
Span::new(Location::new(1, 10), Location::new(1, 11)),
);
// commas @ line 2, column 20
let tok2 = TokenWithLocation::new(
Token::Comma,
Span::new(Location::new(2, 20), Location::new(2, 21)),
);
assert_ne!(tok1, tok2); // token with locations are *not* equal
assert_eq!(AttachedToken(tok1), AttachedToken(tok2)); // attached tokens areDifferent token, different location are equal ๐คฏ
// commas @ line 1, column 10
let tok1 = TokenWithLocation::new(
Token::Comma,
Span::new(Location::new(1, 10), Location::new(1, 11)),
);
// period @ line 2, column 20
let tok2 = TokenWithLocation::new(
Token::Period,
Span::new(Location::new(2, 10), Location::new(2, 21)),
);
assert_ne!(tok1, tok2); // token with locations are *not* equal
assert_eq!(AttachedToken(tok1), AttachedToken(tok2)); // attached tokens are// period @ line 2, column 20
Tuple Fieldsยง
ยง0: TokenWithSpanImplementationsยง
Sourceยงimpl AttachedToken
impl AttachedToken
Sourcepub fn empty() -> AttachedToken
pub fn empty() -> AttachedToken
Return a new Empty AttachedToken
Trait Implementationsยง
Sourceยงimpl Clone for AttachedToken
impl Clone for AttachedToken
Sourceยงfn clone(&self) -> AttachedToken
fn clone(&self) -> AttachedToken
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) ยท Sourceยงfn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSourceยงimpl Debug for AttachedToken
impl Debug for AttachedToken
impl Eq for AttachedToken
Sourceยงimpl From<AttachedToken> for TokenWithSpan
impl From<AttachedToken> for TokenWithSpan
Sourceยงfn from(value: AttachedToken) -> TokenWithSpan
fn from(value: AttachedToken) -> TokenWithSpan
Converts to this type from the input type.
Sourceยงimpl From<TokenWithSpan> for AttachedToken
impl From<TokenWithSpan> for AttachedToken
Sourceยงfn from(value: TokenWithSpan) -> AttachedToken
fn from(value: TokenWithSpan) -> AttachedToken
Converts to this type from the input type.
Sourceยงimpl Hash for AttachedToken
impl Hash for AttachedToken
Sourceยงimpl Ord for AttachedToken
impl Ord for AttachedToken
Sourceยงfn cmp(&self, _: &AttachedToken) -> Ordering
fn cmp(&self, _: &AttachedToken) -> Ordering
1.21.0 (const: unstable) ยท Sourceยงfn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Sourceยงimpl PartialEq for AttachedToken
impl PartialEq for AttachedToken
Sourceยงfn eq(&self, _: &AttachedToken) -> bool
fn eq(&self, _: &AttachedToken) -> bool
Tests for
self and other values to be equal, and is used by ==.Sourceยงimpl PartialOrd for AttachedToken
impl PartialOrd for AttachedToken
Sourceยงimpl Visit for AttachedToken
impl Visit for AttachedToken
Sourceยงimpl VisitMut for AttachedToken
impl VisitMut for AttachedToken
Sourceยงfn visit<V>(&mut self, visitor: &mut V) -> ControlFlow<<V as VisitorMut>::Break>where
V: VisitorMut,
fn visit<V>(&mut self, visitor: &mut V) -> ControlFlow<<V as VisitorMut>::Break>where
V: VisitorMut,
Mutably visit this node with the provided
VisitorMut. Read moreAuto Trait Implementationsยง
impl Freeze for AttachedToken
impl RefUnwindSafe for AttachedToken
impl Send for AttachedToken
impl Sync for AttachedToken
impl Unpin for AttachedToken
impl UnsafeUnpin for AttachedToken
impl UnwindSafe for AttachedToken
Blanket Implementationsยง
Sourceยงimpl<Source> AccessAs for Source
impl<Source> AccessAs for Source
impl<T> Allocation for T
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Sourceยงimpl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Sourceยงimpl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Sourceยงimpl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Sourceยงfn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Sourceยงimpl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Sourceยงimpl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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>
Converts
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>
Converts
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