Skip to content

Commit

Permalink
Add an arrow1 interface on top of ArrowBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Nov 21, 2024
1 parent 56ee284 commit 9d327a5
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions crates/store/re_types_core/src/arrow_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use arrow2::buffer::Buffer;
/// Convenience-wrapper around an arrow [`Buffer`] that is known to contain a
/// a primitive type.
///
/// The arrow2 [`Buffer`] object is internally reference-counted and can be
/// The [`ArrowBuffer`] object is internally reference-counted and can be
/// easily converted back to a `&[T]` referencing the underlying storage.
/// This avoids some of the lifetime complexities that would otherwise
/// arise from returning a `&[T]` directly, but is significantly more
Expand Down Expand Up @@ -50,7 +50,7 @@ impl<T> ArrowBuffer<T> {
self.0.as_slice()
}

/// Returns a new [`Buffer`] that is a slice of this buffer starting at `offset`.
/// Returns a new [`ArrowBuffer`] that is a slice of this buffer starting at `offset`.
///
/// Doing so allows the same memory region to be shared between buffers.
///
Expand Down Expand Up @@ -95,9 +95,18 @@ impl<T: Clone> ArrowBuffer<T> {
}
}

impl<T> From<Buffer<T>> for ArrowBuffer<T> {
impl<T: arrow::datatypes::ArrowNativeType + arrow2::types::NativeType>
From<arrow::buffer::ScalarBuffer<T>> for ArrowBuffer<T>
{
#[inline]
fn from(value: Buffer<T>) -> Self {
fn from(value: arrow::buffer::ScalarBuffer<T>) -> Self {
Self(value.into_inner().into())
}
}

impl<T> From<arrow2::buffer::Buffer<T>> for ArrowBuffer<T> {
#[inline]
fn from(value: arrow2::buffer::Buffer<T>) -> Self {
Self(value)
}
}
Expand All @@ -118,7 +127,7 @@ impl<T: Clone> From<&[T]> for ArrowBuffer<T> {

impl<T> FromIterator<T> for ArrowBuffer<T> {
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {
Self(Buffer::from_iter(iter))
Self(arrow2::buffer::Buffer::from_iter(iter))
}
}

Expand Down

0 comments on commit 9d327a5

Please sign in to comment.