Struct arrow::buffer::Buffer [−][src]
pub struct Buffer { /* fields omitted */ }
Expand description
Buffer represents a contiguous memory region that can be shared with other buffers and across thread boundaries.
Implementations
Auxiliary method to create a new Buffer
Initializes a Buffer from a slice of items.
Creates a buffer from an existing memory region (must already be byte-aligned), this
Buffer
will free this piece of memory when dropped.
Arguments
ptr
- Pointer to raw partslen
- Length of raw parts in bytescapacity
- Total allocated memory for the pointerptr
, in bytes
Safety
This function is unsafe as there is no guarantee that the given pointer is valid for len
bytes. If the ptr
and capacity
come from a Buffer
, then this is guaranteed.
Creates a buffer from an existing memory region (must already be byte-aligned), this
Buffer
does not free this piece of memory when dropped.
Arguments
ptr
- Pointer to raw partslen
- Length of raw parts in bytesdata
- An ffi::FFI_ArrowArray with the data
Safety
This function is unsafe as there is no guarantee that the given pointer is valid for len
bytes and that the foreign deallocator frees the region.
Returns the capacity of this buffer. For exernally owned buffers, this returns zero
Returns a pointer to the start of this buffer.
Note that this should be used cautiously, and the returned pointer should not be stored anywhere, to avoid dangling pointers.
View buffer as typed slice.
Safety
ArrowNativeType
is public so that it can be used as a trait bound for other public
components, such as the ToByteSlice
trait. However, this means that it can be
implemented by user defined types, which it is not intended for.
Also typed_data::<bool>
is unsafe as 0x00
and 0x01
are the only valid values for
bool
in Rust. However, bool
arrays in Arrow are bit-packed which breaks this condition.
View buffer as typed slice.
Returns a slice of this buffer starting at a certain bit offset. If the offset is byte-aligned the returned buffer is a shallow clone, otherwise a new buffer is allocated and filled with a copy of the bits in the range.
Returns a BitChunks
instance which can be used to iterate over this buffers bits
in larger chunks and starting at arbitrary bit offsets.
Note that both offset
and length
are measured in bits.
Returns the number of 1-bits in this buffer.
Returns the number of 1-bits in this buffer, starting from offset
with length
bits
inspected. Note that both offset
and length
are measured in bits.
pub unsafe fn from_trusted_len_iter<T: ArrowNativeType, I: Iterator<Item = T>>(
iterator: I
) -> Self
pub unsafe fn from_trusted_len_iter<T: ArrowNativeType, I: Iterator<Item = T>>(
iterator: I
) -> Self
Creates a Buffer
from an Iterator
with a trusted (upper) length.
Prefer this to collect
whenever possible, as it is ~60% faster.
Example
let v = vec![1u32];
let iter = v.iter().map(|x| x * 2);
let buffer = unsafe { Buffer::from_trusted_len_iter(iter) };
assert_eq!(buffer.len(), 4) // u32 has 4 bytes
Safety
This method assumes that the iterator’s size is correct and is undefined behavior to use it on an iterator that reports an incorrect length.
pub unsafe fn try_from_trusted_len_iter<E, T: ArrowNativeType, I: Iterator<Item = Result<T, E>>>(
iterator: I
) -> Result<Self, E>
pub unsafe fn try_from_trusted_len_iter<E, T: ArrowNativeType, I: Iterator<Item = Result<T, E>>>(
iterator: I
) -> Result<Self, E>
Creates a Buffer
from an Iterator
with a trusted (upper) length or errors
if any of the items of the iterator is an error.
Prefer this to collect
whenever possible, as it is ~60% faster.
Safety
This method assumes that the iterator’s size is correct and is undefined behavior to use it on an iterator that reports an incorrect length.
Trait Implementations
Performs the conversion.
Performs the conversion.
Creating a Buffer
instance by copying the memory from a AsRef<[u8]>
into a newly
allocated memory region.
Creates a value from an iterator. Read more
Creating a Buffer
instance by storing the boolean values into the buffer
Creates a value from an iterator. Read more
Auto Trait Implementations
Blanket Implementations
Mutably borrows from an owned value. Read more