You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by su...@apache.org on 2019/05/10 04:26:18 UTC

[arrow] branch master updated: ARROW-5298: [Rust] Add debug implementation for buffer data.

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

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


The following commit(s) were added to refs/heads/master by this push:
     new a1cb373  ARROW-5298: [Rust] Add debug implementation for buffer data.
a1cb373 is described below

commit a1cb37333fb54774940a71bf028f479dea11c3a4
Author: Renjie Liu <li...@gmail.com>
AuthorDate: Thu May 9 21:26:05 2019 -0700

    ARROW-5298: [Rust] Add debug implementation for buffer data.
    
    Default debug implementation for buffer data is not good enough for debugging.
    
    Author: Renjie Liu <li...@gmail.com>
    
    Closes #4287 from liurenjie1024/arrow-5298 and squashes the following commits:
    
    fd5df7aa <Renjie Liu> Add buffer implementation for buffer data
---
 rust/arrow/src/buffer.rs | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/rust/arrow/src/buffer.rs b/rust/arrow/src/buffer.rs
index ff4cae8..7b3222d 100644
--- a/rust/arrow/src/buffer.rs
+++ b/rust/arrow/src/buffer.rs
@@ -22,6 +22,7 @@
 use packed_simd::u8x64;
 
 use std::cmp;
+use std::fmt::{Debug, Formatter};
 use std::io::{Error as IoError, ErrorKind, Result as IoResult, Write};
 use std::mem;
 use std::ops::{BitAnd, BitOr, Not};
@@ -44,7 +45,6 @@ pub struct Buffer {
     offset: usize,
 }
 
-#[derive(Debug)]
 struct BufferData {
     /// The raw pointer into the buffer bytes
     ptr: *const u8,
@@ -69,6 +69,24 @@ impl Drop for BufferData {
     }
 }
 
+impl Debug for BufferData {
+    fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
+        write!(
+            f,
+            "BufferData {{ ptr: {:?}, len: {}, data: ",
+            self.ptr, self.len
+        )?;
+
+        unsafe {
+            f.debug_list()
+                .entries(std::slice::from_raw_parts(self.ptr, self.len).iter())
+                .finish()?;
+        }
+
+        write!(f, " }}")
+    }
+}
+
 impl Buffer {
     /// Creates a buffer from an existing memory region (must already be byte-aligned)
     pub fn from_raw_parts(ptr: *const u8, len: usize) -> Self {