Skip to main content

View

Trait View 

Source
pub trait View:
    MaskedArray
    + Into<Array>
    + Clone
where Self::Container: AsRef<[Self::BufferT]>,
{ type BufferT: Default + PartialEq + Clone + Copy; // Provided methods fn as_slice(&self) -> &[Self::BufferT] { ... } fn slice( &self, offset: usize, len: usize, ) -> (&[Self::BufferT], usize, usize) { ... } fn view(self, offset: usize, len: usize) -> ArrayV { ... } fn view_tuple(self, offset: usize, len: usize) -> (Array, usize, usize) { ... } }
Expand description

§View trait

Zero-copy, windowed access to array data with multiple abstraction levels.

§Description

The View trait provides a unified interface for creating logical subviews into arrays without duplicating their underlying buffers. It is implemented by all MaskedArray types and supports three main access patterns:

  • Native slice access – direct &[T] or &[u8] for fixed- and variable-width data.
  • ArrayView – an Arc-cloned, type-aware view with safe windowing and typed accessors.
  • TupleView – a minimal (&Array, offset, length) form for maximum performance.

§Purpose

This trait indirectly supports pipelines, joins, and analytics that need read-only subsets of arrays without the cost of copying or reallocating.

§Ownership Semantics

  • When called on an Arc-wrapped array (e.g., Array), .view() consumes the Arc. Clone the Arc first if you need to retain the original.
  • When called on a direct array variant, .view() consumes ownership. Wrap in Array first if you need continued access.

§Behaviour

  • Views enforce logical offset/length constraints.
  • Access methods such as .num(), .text(), .dt(), .bool() return typed view variants.
  • Always zero-copy: only offset and length metadata change, not the backing buffers.

§Compared to Apache Arrow

Arrow arrays are lightweight views over reference-counted buffers (the view + buffers are separate types). In MinArrow, an Array already owns an Arc to its inner buffers; a View (e.g., ArrayV) simply adds window (offset/length) metadata on top of that same Arc’d data. In both designs there’s effectively one layer of ref counting; the key difference is that Apache Arrow bakes “view-ness” into the array type itself, whereas MinArrow keeps arrays concrete and layers windowing as a separate view.

Required Associated Types§

Source

type BufferT: Default + PartialEq + Clone + Copy

The fixed-width buffer type (e.g. u8, f32, bool, etc.)

Provided Methods§

Source

fn as_slice(&self) -> &[Self::BufferT]

Returns the whole array buffer as a &[T] slice.

Source

fn slice(&self, offset: usize, len: usize) -> (&[Self::BufferT], usize, usize)

Slices the data values from offset to offset + length.

§Parameters
  • offset: Starting index.
  • len: Number of elements.
§Returns

A native slice of the data values.

Source

fn view(self, offset: usize, len: usize) -> ArrayV

Returns a zero-copy, windowed view (ArrayView) into this array.

§Ownership Semantics
  • For Arc-wrapped arrays (e.g., Array), this method consumes the Arc. If you need to retain access to the original array after calling view, clone the Arc at the call site (cheap pointer clone).
  • For direct array variants (e.g., IntegerArray<u64>), calling view consumes ownership. If continued access to the original is required, promote the variant into an Arc (or Array) first.
§Behaviour
  • The returned ArrayView enforces the window (offset, length) and provides safe, zero-copy access.
  • The backing array remains accessible via &Array within the view.
  • Type-specific accessors (.num(), .str(), .bool(), .dt()) are available on ArrayView for ergonomic, typed access.
§Implementation Notes
  • Unlike Apache Arrow, where arrays are trait-based views over reference-counted buffers, MinArrow uses a concrete Array struct which already holds a zero-copy Arc reference to its inner array data.
  • ArrayView therefore provides a windowed zero-copy view into a specific region of this array.
§Parameters
  • offset: The logical start index for the window.
  • len: The logical length of the window.
§Returns

An ArrayView representing the specified logical window.

Source

fn view_tuple(self, offset: usize, len: usize) -> (Array, usize, usize)

Returns a tuple view of (&Array, offset, length).

§Parameters
  • offset: Starting index.
  • length: Number of elements.
§Returns

Tuple containing array reference, offset, and length.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl View for Arc<BooleanArray<()>>

Available on crate feature views only.
Source§

impl View for Arc<CategoricalArray<u8>>

Available on crate features default_categorical_8 and views only.
Source§

impl View for Arc<FloatArray<f32>>

Available on crate feature views only.
Source§

impl View for Arc<FloatArray<f64>>

Available on crate feature views only.
Source§

impl View for Arc<IntegerArray<i32>>

Available on crate feature views only.
Source§

impl View for Arc<IntegerArray<i64>>

Available on crate feature views only.
Source§

impl View for Arc<IntegerArray<u32>>

Available on crate feature views only.
Source§

impl View for Arc<IntegerArray<u64>>

Available on crate feature views only.
Source§

impl View for Arc<StringArray<u32>>

Available on crate feature views only.
Source§

impl View for Arc<StringArray<u64>>

Available on crate features large_string and views only.

Implementors§

Source§

impl View for BooleanArray<()>

Available on crate feature views only.
Source§

impl View for CategoricalArray<u8>

Available on crate features default_categorical_8 and views only.
Source§

impl View for FloatArray<f32>

Available on crate feature views only.
Source§

impl View for FloatArray<f64>

Available on crate feature views only.
Source§

impl View for IntegerArray<i32>

Available on crate feature views only.
Source§

impl View for IntegerArray<i64>

Available on crate feature views only.
Source§

impl View for IntegerArray<u32>

Available on crate feature views only.
Source§

impl View for IntegerArray<u64>

Available on crate feature views only.
Source§

impl View for StringArray<u32>

Available on crate feature views only.
Source§

impl View for StringArray<u64>

Available on crate features large_string and views only.