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 ยท 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
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 ยท 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ยงimpl PartialOrd for AttachedToken
impl PartialOrd for AttachedToken
impl Eq for AttachedToken
Auto 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<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