work
authorBen Pfaff <blp@cs.stanford.edu>
Mon, 19 May 2025 15:19:38 +0000 (08:19 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Mon, 19 May 2025 15:19:38 +0000 (08:19 -0700)
rust/pspp/src/dictionary.rs
rust/pspp/src/sys/raw.rs

index d0e2080fd1fd77310dea8592eb3f074d1061fa3c..0a93e0c6397375dbd36b83dae61ddcc11703a520 100644 (file)
@@ -191,7 +191,10 @@ where
     }
 }
 
-impl PartialEq for Value {
+impl<S> PartialEq for Value<S>
+where
+    S: PartialEq,
+{
     fn eq(&self, other: &Self) -> bool {
         match (self, other) {
             (Self::Number(Some(l0)), Self::Number(Some(r0))) => {
@@ -204,7 +207,7 @@ impl PartialEq for Value {
     }
 }
 
-impl Eq for Value {}
+impl<S> Eq for Value<S> where S: Eq {}
 
 impl PartialOrd for Value {
     fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
@@ -228,7 +231,10 @@ impl Ord for Value {
     }
 }
 
-impl Hash for Value {
+impl<S> Hash for Value<S>
+where
+    S: Hash,
+{
     fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
         match self {
             Value::Number(number) => number.map(OrderedFloat).hash(state),
@@ -663,7 +669,7 @@ pub struct Variable {
 
     /// Value labels, to associate a number (or a string) with a more meaningful
     /// description, e.g. 1 -> Apple, 2 -> Banana, ...
-    pub value_labels: HashMap<Value, String>,
+    pub value_labels: HashMap<Value<EncodedString>, String>,
 
     /// Variable label, an optional meaningful description for the variable
     /// itself.
index 18daf2cef709fb790eb938c0c3a2efd7fce8b24a..5fb598954f69b6cdd088e8cfd321e1b992ee35dc 100644 (file)
@@ -1558,7 +1558,7 @@ impl<const N: usize> Debug for RawStrArray<N> {
 /// have the same contents.  This is an important optimization for hashing:
 /// otherwise, strings could only be hashed if they were converted to a common
 /// encoding (probably UTF-8), which would be expensive.
-#[derive(Clone)]
+#[derive(Clone, Eq, Hash)]
 pub struct EncodedString {
     /// Raw contents.
     bytes: RawString,