MCPcopy Create free account
hub / github.com/apache/arrow-rs / into_vec

Method into_vec

arrow-buffer/src/buffer/immutable.rs:409–442  ·  view source on GitHub ↗

Converts self into a `Vec`, if possible. This can be used to reuse / mutate the underlying data. # Errors Returns `Err(self)` if 1. The buffer does not have the same [`Layout`] as the destination Vec 2. The buffer contains a non-zero offset 3. The buffer is shared

(self)

Source from the content-addressed store, hash-verified

407 /// 2. The buffer contains a non-zero offset
408 /// 3. The buffer is shared
409 pub fn into_vec<T: ArrowNativeType>(self) -> Result<Vec<T>, Self> {
410 let layout = match self.data.deallocation() {
411 Deallocation::Standard(l) => l,
412 _ => return Err(self), // Custom allocation
413 };
414
415 if self.ptr != self.data.as_ptr() {
416 return Err(self); // Data is offset
417 }
418
419 let v_capacity = layout.size() / std::mem::size_of::<T>();
420 match Layout::array::<T>(v_capacity) {
421 Ok(expected) if layout == &expected => {}
422 _ => return Err(self), // Incorrect layout
423 }
424
425 let length = self.length;
426 let ptr = self.ptr;
427 let v_len = self.length / std::mem::size_of::<T>();
428
429 Arc::try_unwrap(self.data)
430 .map(|bytes| unsafe {
431 let ptr = bytes.ptr().as_ptr() as _;
432 std::mem::forget(bytes);
433 // Safety
434 // Verified that bytes layout matches that of Vec
435 Vec::from_raw_parts(ptr, v_len, v_capacity)
436 })
437 .map_err(|bytes| Buffer {
438 data: bytes,
439 ptr,
440 length,
441 })
442 }
443
444 /// Returns true if this [`Buffer`] is equal to `other`, using pointer comparisons
445 /// to determine buffer equality. This is cheaper than `PartialEq::eq` but may

Callers 2

fromMethod · 0.80
from_binaryMethod · 0.80

Calls 4

ptrMethod · 0.80
deallocationMethod · 0.45
as_ptrMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected