Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4dd147b

Browse files
emilkmbrobbel
andauthoredApr 15, 2025··
Implement Eq for ScalarBuffer when T: Eq (#7412)
* Implement Eq for ScalarBuffer when possible * fix typo Co-authored-by: Matthijs Brobbel <m1brobbel@gmail.com> --------- Co-authored-by: Matthijs Brobbel <m1brobbel@gmail.com>
1 parent 7f3907e commit 4dd147b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
 

Diff for: ‎arrow-buffer/src/buffer/scalar.rs

+18
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ impl<T: ArrowNativeType> PartialEq<ScalarBuffer<T>> for Vec<T> {
221221
}
222222
}
223223

224+
/// If T implements Eq, then so does ScalarBuffer.
225+
impl<T: ArrowNativeType + Eq> Eq for ScalarBuffer<T> {}
226+
224227
#[cfg(test)]
225228
mod tests {
226229
use std::{ptr::NonNull, sync::Arc};
@@ -342,4 +345,19 @@ mod tests {
342345
assert_eq!(vec, input.as_slice());
343346
assert_ne!(vec.as_ptr(), input.as_ptr());
344347
}
348+
349+
#[test]
350+
fn scalar_buffer_impl_eq() {
351+
fn are_equal<T: Eq>(a: &T, b: &T) -> bool {
352+
a.eq(b)
353+
}
354+
355+
assert!(
356+
are_equal(
357+
&ScalarBuffer::<i16>::from(vec![23]),
358+
&ScalarBuffer::<i16>::from(vec![23])
359+
),
360+
"ScalarBuffer should implement Eq if the inner type does"
361+
);
362+
}
345363
}

0 commit comments

Comments
 (0)
Please sign in to comment.