[ 
https://issues.apache.org/jira/browse/ARROW-2408?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16430486#comment-16430486
 ] 

ASF GitHub Bot commented on ARROW-2408:
---------------------------------------

pitrou closed pull request #1846: ARROW-2408: [Rust] Ability to get `&mut [T]` 
from `Buffer<T>`
URL: https://github.com/apache/arrow/pull/1846
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/rust/examples/array_from_builder.rs 
b/rust/examples/array_from_builder.rs
index 3a273a64d..ea1ecec45 100644
--- a/rust/examples/array_from_builder.rs
+++ b/rust/examples/array_from_builder.rs
@@ -18,7 +18,6 @@
 extern crate arrow;
 
 use arrow::array::*;
-use arrow::buffer::*;
 use arrow::builder::*;
 
 fn main() {
diff --git a/rust/src/buffer.rs b/rust/src/buffer.rs
index ab90a5b08..1f2ec6c8d 100644
--- a/rust/src/buffer.rs
+++ b/rust/src/buffer.rs
@@ -18,7 +18,6 @@
 use bytes::Bytes;
 use libc;
 use std::mem;
-use std::ptr;
 use std::slice;
 
 use super::memory::*;
diff --git a/rust/src/builder.rs b/rust/src/builder.rs
index 1cc024042..ebdf3a942 100644
--- a/rust/src/builder.rs
+++ b/rust/src/builder.rs
@@ -15,7 +15,6 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use bytes::Bytes;
 use libc;
 use std::mem;
 use std::ptr;
@@ -48,6 +47,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());


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> [Rust] It should be possible to get a &mut[T] from Builder<T>
> -------------------------------------------------------------
>
>                 Key: ARROW-2408
>                 URL: https://issues.apache.org/jira/browse/ARROW-2408
>             Project: Apache Arrow
>          Issue Type: New Feature
>          Components: Rust
>            Reporter: Andy Grove
>            Assignee: Andy Grove
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 0.10.0
>
>
> I am currently adding Arrow support to the parquet-rs crate and I found a 
> need to get a mutable slice from a Buffer<T> to pass to the parquet column 
> reader methods.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to