Skip to content

Commit

Permalink
implement Hash and Eq for ResolvedNode and ResolvedToken.
Browse files Browse the repository at this point in the history
These simply forward to the impls for SyntaxNode and SyntaxToken respectivly.
  • Loading branch information
aDotInTheVoid committed Aug 20, 2024
1 parent 1babdb0 commit 51e673f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions cstree/src/syntax/resolved.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use std::{
fmt,
hash::Hash,
ops::{Deref, DerefMut},
sync::Arc as StdArc,
};
Expand Down Expand Up @@ -65,6 +66,18 @@ impl<S: Syntax, D> DerefMut for ResolvedNode<S, D> {
}
}

impl<S: Syntax, D> PartialEq for ResolvedNode<S, D> {
fn eq(&self, other: &Self) -> bool {
self.syntax == other.syntax
}
}
impl<S: Syntax, D> Eq for ResolvedNode<S, D> {}
impl<S: Syntax, D> Hash for ResolvedNode<S, D> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.syntax.hash(state);
}
}

/// Syntax tree token that is guaranteed to belong to a tree that contains an associated
/// [`Resolver`](lasso::Resolver).
/// # See also
Expand Down Expand Up @@ -109,6 +122,18 @@ impl<S: Syntax, D> DerefMut for ResolvedToken<S, D> {
}
}

impl<S: Syntax, D> PartialEq for ResolvedToken<S, D> {
fn eq(&self, other: &Self) -> bool {
self.syntax == other.syntax
}
}
impl<S: Syntax, D> Eq for ResolvedToken<S, D> {}
impl<S: Syntax, D> Hash for ResolvedToken<S, D> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.syntax.hash(state);
}
}

/// An element of the tree that is guaranteed to belong to a tree that contains an associated
/// [`Resolver`](lasso::Resolver), can be either a node or a token.
///
Expand Down

0 comments on commit 51e673f

Please sign in to comment.