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

apitrou 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 abf4ed2  ARROW-2408: [Rust] Ability to get `&mut [T]` from `Buffer<T>`
abf4ed2 is described below

commit abf4ed2ef9483a1dd8ac8a0b285a0b43eace34f7
Author: Andy Grove <andygrov...@gmail.com>
AuthorDate: Mon Apr 9 14:54:36 2018 +0200

    ARROW-2408: [Rust] Ability to get `&mut [T]` from `Buffer<T>`
    
    Author: Andy Grove <andygrov...@gmail.com>
    
    Closes #1846 from andygrove/builder_get_slice_mut and squashes the 
following commits:
    
    74043c3 <Andy Grove> add assertions to make slice_mut safe
    758cf26 <Andy Grove> rustfmt and clean up unused imports
---
 rust/src/builder.rs | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/rust/src/builder.rs b/rust/src/builder.rs
index c8ba274..58e5a12 100644
--- a/rust/src/builder.rs
+++ b/rust/src/builder.rs
@@ -46,6 +46,21 @@ impl<T> Builder<T> {
         }
     }
 
+    /// Get the internal byte-aligned memory buffer as a mutable slice
+    pub fn slice_mut(&self, start: usize, end: usize) -> &mut [T] {
+        assert!(start <= end);
+        assert!(start < self.len as usize);
+        assert!(end <= self.len as usize);
+        unsafe {
+            slice::from_raw_parts_mut(self.data.offset(start as isize), (end - 
start) as usize)
+        }
+    }
+
+    /// Override the length
+    pub fn set_len(&mut self, len: usize) {
+        self.len = len;
+    }
+
     /// Push a value into the builder, growing the internal buffer as needed
     pub fn push(&mut self, v: T) {
         assert!(!self.data.is_null());

-- 
To stop receiving notification emails like this one, please contact
apit...@apache.org.

Reply via email to