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

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


The following commit(s) were added to refs/heads/master by this push:
     new dc23fa3ba Improve ScalarBuffer debug output (#3907)
dc23fa3ba is described below

commit dc23fa3badbc9605e2439983439befaca0647fe9
Author: Raphael Taylor-Davies <[email protected]>
AuthorDate: Wed Mar 22 18:21:51 2023 +0000

    Improve ScalarBuffer debug output (#3907)
---
 arrow-buffer/src/buffer/scalar.rs | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/arrow-buffer/src/buffer/scalar.rs 
b/arrow-buffer/src/buffer/scalar.rs
index 04c6d9dcc..4c16a736b 100644
--- a/arrow-buffer/src/buffer/scalar.rs
+++ b/arrow-buffer/src/buffer/scalar.rs
@@ -17,6 +17,7 @@
 
 use crate::buffer::Buffer;
 use crate::native::ArrowNativeType;
+use std::fmt::Formatter;
 use std::marker::PhantomData;
 use std::ops::Deref;
 
@@ -26,13 +27,19 @@ use std::ops::Deref;
 ///
 /// All [`ArrowNativeType`] are valid for all possible backing byte 
representations, and as
 /// a result they are "trivially safely transmutable".
-#[derive(Debug, Clone)]
+#[derive(Clone)]
 pub struct ScalarBuffer<T: ArrowNativeType> {
     /// Underlying data buffer
     buffer: Buffer,
     phantom: PhantomData<T>,
 }
 
+impl<T: ArrowNativeType> std::fmt::Debug for ScalarBuffer<T> {
+    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+        f.debug_tuple("ScalarBuffer").field(&self.as_ref()).finish()
+    }
+}
+
 impl<T: ArrowNativeType> ScalarBuffer<T> {
     /// Create a new [`ScalarBuffer`] from a [`Buffer`], and an `offset`
     /// and `length` in units of `T`
@@ -168,6 +175,12 @@ mod tests {
         assert!(typed.is_empty());
     }
 
+    #[test]
+    fn test_debug() {
+        let buffer = ScalarBuffer::from(vec![1, 2, 3]);
+        assert_eq!(format!("{buffer:?}"), "ScalarBuffer([1, 2, 3])");
+    }
+
     #[test]
     #[should_panic(expected = "memory is not aligned")]
     fn test_unaligned() {

Reply via email to