This is an automated email from the ASF dual-hosted git repository.

jayzhan pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/main by this push:
     new 4dd147bc69 Implement `Eq` for `ScalarBuffer` when `T: Eq` (#7412)
4dd147bc69 is described below

commit 4dd147bc6909230a1f06df637f2d2a58b2f0d18f
Author: Emil Ernerfeldt <[email protected]>
AuthorDate: Tue Apr 15 03:05:34 2025 +0200

    Implement `Eq` for `ScalarBuffer` when `T: Eq` (#7412)
    
    * Implement Eq for ScalarBuffer when possible
    
    * fix typo
    
    Co-authored-by: Matthijs Brobbel <[email protected]>
    
    ---------
    
    Co-authored-by: Matthijs Brobbel <[email protected]>
---
 arrow-buffer/src/buffer/scalar.rs | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/arrow-buffer/src/buffer/scalar.rs 
b/arrow-buffer/src/buffer/scalar.rs
index 94dd7bcfc2..36ee15718b 100644
--- a/arrow-buffer/src/buffer/scalar.rs
+++ b/arrow-buffer/src/buffer/scalar.rs
@@ -221,6 +221,9 @@ impl<T: ArrowNativeType> PartialEq<ScalarBuffer<T>> for 
Vec<T> {
     }
 }
 
+/// If T implements Eq, then so does ScalarBuffer.
+impl<T: ArrowNativeType + Eq> Eq for ScalarBuffer<T> {}
+
 #[cfg(test)]
 mod tests {
     use std::{ptr::NonNull, sync::Arc};
@@ -342,4 +345,19 @@ mod tests {
         assert_eq!(vec, input.as_slice());
         assert_ne!(vec.as_ptr(), input.as_ptr());
     }
+
+    #[test]
+    fn scalar_buffer_impl_eq() {
+        fn are_equal<T: Eq>(a: &T, b: &T) -> bool {
+            a.eq(b)
+        }
+
+        assert!(
+            are_equal(
+                &ScalarBuffer::<i16>::from(vec![23]),
+                &ScalarBuffer::<i16>::from(vec![23])
+            ),
+            "ScalarBuffer should implement Eq if the inner type does"
+        );
+    }
 }

Reply via email to