Skip to content

Commit 4dd147b

Browse files
emilkmbrobbel
andauthored
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]>
1 parent 7f3907e commit 4dd147b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

arrow-buffer/src/buffer/scalar.rs

Lines changed: 18 additions & 0 deletions
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)