pub struct AttachedToken(pub TokenWithSpan);
Expand description
A wrapper over TokenWithSpan
s 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 are
Different 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: TokenWithSpan
Implementationsยง
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<'de> Deserialize<'de> for AttachedToken
impl<'de> Deserialize<'de> for AttachedToken
Sourceยงfn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Sourceยงimpl From<AttachedToken> for TokenWithSpan
impl From<AttachedToken> for TokenWithSpan
Sourceยงfn from(value: AttachedToken) -> Self
fn from(value: AttachedToken) -> Self
Converts to this type from the input type.
Sourceยงimpl From<TokenWithSpan> for AttachedToken
impl From<TokenWithSpan> for AttachedToken
Sourceยงfn from(value: TokenWithSpan) -> Self
fn from(value: TokenWithSpan) -> Self
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ยงimpl PartialEq for AttachedToken
impl PartialEq for AttachedToken
Sourceยงimpl PartialOrd for AttachedToken
impl PartialOrd for AttachedToken
Sourceยงimpl Serialize for AttachedToken
impl Serialize for AttachedToken
Sourceยงimpl Visit for AttachedToken
impl Visit for AttachedToken
Sourceยงimpl VisitMut for AttachedToken
impl VisitMut for AttachedToken
fn visit<V: VisitorMut>(&mut self, visitor: &mut V) -> ControlFlow<V::Break>
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 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