Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement Hash and Eq for ResolvedNode and ResolvedToken. #63

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

* Implement `Hash` and `Eq` for `ResolvedNode` and `ResolvedToken`

## `v0.12.0`

* Documentation has been improved in most areas, together with a switch to a more principled module structure that allows explicitly documenting submodules.
Expand Down
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
Loading