Skip to content

Commit 5a2ca0e

Browse files
committed
fix(utils): Derive Hash manually
in `input/layout` since the `PartialEq` trait is also implemented manually. Previously the `Hash` impl wasn't consistent with the `Eq` impl, which can have weird effects when using these types in e.g. `HashMap`s or similar types. For additional information, see: - https://rust-lang.github.io/rust-clippy/master/index.html#derived_hash_with_manual_eq - https://doc.rust-lang.org/stable/std/hash/trait.Hash.html#hash-and-eq
1 parent a9aa1c3 commit 5a2ca0e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

zellij-utils/src/input/layout.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ impl RunPlugin {
433433
}
434434
}
435435

436-
#[derive(Debug, Serialize, Deserialize, Clone, Hash, Default, Eq)]
436+
#[derive(Debug, Serialize, Deserialize, Clone, Default, Eq)]
437437
pub struct PluginAlias {
438438
pub name: String,
439439
pub configuration: Option<PluginUserConfiguration>,
@@ -443,10 +443,19 @@ pub struct PluginAlias {
443443

444444
impl PartialEq for PluginAlias {
445445
fn eq(&self, other: &Self) -> bool {
446+
// NOTE: Keep this in sync with what the `Hash` trait impl does.
446447
self.name == other.name && self.configuration == other.configuration
447448
}
448449
}
449450

451+
impl std::hash::Hash for PluginAlias {
452+
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
453+
// NOTE: Keep this in sync with what the `PartiqlEq` trait impl does.
454+
self.name.hash(state);
455+
self.configuration.hash(state);
456+
}
457+
}
458+
450459
impl PluginAlias {
451460
pub fn new(
452461
name: &str,

0 commit comments

Comments
 (0)