Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve ScalarBuffer debug output #3907

Merged
merged 1 commit into from
Mar 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion arrow-buffer/src/buffer/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

use crate::buffer::Buffer;
use crate::native::ArrowNativeType;
use std::fmt::Formatter;
use std::marker::PhantomData;
use std::ops::Deref;

Expand All @@ -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`
Expand Down Expand Up @@ -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() {
Expand Down