1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// Copyright 2025 Peter Garfield Bower
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! # **View Trait Module** - *Standardises Slicing and View Moves in Minarrow*
//!
//! Zero-copy array view abstractions for `MinArrow`.
//!
//! This module defines the [`View`] trait, which provides a unified interface
//! for creating lightweight, zero-copy “windows” into arrays without duplicating
//! their underlying buffers.
//!
//! It supports three main access patterns:
//! - **Native slices** – direct `&[T]` or `&[u8]` access for fixed- and variable-width types.
//! - **ArrayView** – a typed, windowed view backed by `Arc`-cloned array data.
//! - **TupleView** – a minimal `(&Array, offset, length)` form for maximum performance.
//!
//! These views allow efficient subsetting, iteration, and type-specific access
//! (`.num()`, `.text()`, `.dt()`, `.bool()`), while preserving the semantics of
//! the original array type.
//!
//! Unlike Apache Arrow’s trait-based array references, `MinArrow` stores its arrays
//! in a concrete [`Array`] type already holding an `Arc` to its inner buffers.
//! This means `ArrayView` only needs to enforce logical offset/length constraints,
//! avoiding additional indirection or ref-counting overhead.
//!
//! Use these abstractions in pipelines, joins, and analytic operations where you
//! need read-only views over subsets of arrays without copying or reallocation.
use crate::;
/// # 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.