Skip to content

Commit 7446662

Browse files
committed
fix(template): fix interior mutability issue by formalizing the hash function
1 parent 0e3cecf commit 7446662

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/pipeline/template.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,32 @@ impl Display for MultiTemplate {
983983
}
984984
}
985985

986+
/// Hash implementation based only on the template string content.
987+
///
988+
/// This implementation ignores interior mutability in parsed operations and
989+
/// caches, making it safe to use MultiTemplate as a key in hash collections.
990+
/// Two templates with the same string content will always hash equally.
991+
impl Hash for MultiTemplate {
992+
fn hash<H: Hasher>(&self, state: &mut H) {
993+
self.raw.hash(state);
994+
}
995+
}
996+
997+
/// Equality implementation based only on the template string content.
998+
///
999+
/// Two templates are considered equal if they have the same raw template string,
1000+
/// regardless of their internal state or cached operations.
1001+
impl PartialEq for MultiTemplate {
1002+
fn eq(&self, other: &Self) -> bool {
1003+
self.raw == other.raw
1004+
}
1005+
}
1006+
1007+
/// Equivalence relation implementation.
1008+
///
1009+
/// Required for use as keys in hash collections. Based on template string equality.
1010+
impl Eq for MultiTemplate {}
1011+
9861012
/* ---------- backward compatibility alias --------------------------------- */
9871013

9881014
/// Type alias for backward compatibility.

0 commit comments

Comments
 (0)