@@ -10,7 +10,9 @@ use vortex_dtype::DType;
1010use vortex_error:: vortex_panic;
1111
1212use super :: macros:: match_each_vector_mut;
13- use crate :: { BoolVectorMut , NullVectorMut , PrimitiveVectorMut , Vector , VectorMutOps } ;
13+ use crate :: {
14+ BoolVectorMut , NullVectorMut , PrimitiveVectorMut , StructVectorMut , Vector , VectorMutOps ,
15+ } ;
1416
1517/// An enum over all kinds of mutable vectors, which represent fully decompressed (canonical) array
1618/// data.
@@ -23,15 +25,17 @@ use crate::{BoolVectorMut, NullVectorMut, PrimitiveVectorMut, Vector, VectorMutO
2325/// [`VectorOps`](crate::VectorOps) trait.
2426#[ derive( Debug , Clone ) ]
2527pub enum VectorMut {
26- /// Null mutable vectors.
28+ /// Mutable Null vectors.
2729 Null ( NullVectorMut ) ,
28- /// Boolean mutable vectors.
30+ /// Mutable Boolean vectors.
2931 Bool ( BoolVectorMut ) ,
30- /// Primitive mutable vectors.
32+ /// Mutable Primitive vectors.
3133 ///
3234 /// Note that [`PrimitiveVectorMut`] is an enum over the different possible (generic)
3335 /// [`PVecMut<T>`](crate::PVecMut)s. See the documentation for more information.
3436 Primitive ( PrimitiveVectorMut ) ,
37+ /// Mutable vectors of Struct elements.
38+ Struct ( StructVectorMut ) ,
3539}
3640
3741impl VectorMut {
@@ -95,29 +99,69 @@ impl VectorMutOps for VectorMut {
9599}
96100
97101impl VectorMut {
98- /// Convert into NullVectorMut, panicking if the type does not match.
102+ /// Returns a reference to the inner [`NullVectorMut`] if `self` is of that variant.
103+ pub fn as_null ( & self ) -> & NullVectorMut {
104+ if let VectorMut :: Null ( v) = self {
105+ return v;
106+ }
107+ vortex_panic ! ( "Expected NullVectorMut, got {self:?}" ) ;
108+ }
109+
110+ /// Returns a reference to the inner [`BoolVectorMut`] if `self` is of that variant.
111+ pub fn as_bool ( & self ) -> & BoolVectorMut {
112+ if let VectorMut :: Bool ( v) = self {
113+ return v;
114+ }
115+ vortex_panic ! ( "Expected BoolVectorMut, got {self:?}" ) ;
116+ }
117+
118+ /// Returns a reference to the inner [`PrimitiveVectorMut`] if `self` is of that variant.
119+ pub fn as_primitive ( & self ) -> & PrimitiveVectorMut {
120+ if let VectorMut :: Primitive ( v) = self {
121+ return v;
122+ }
123+ vortex_panic ! ( "Expected PrimitiveVectorMut, got {self:?}" ) ;
124+ }
125+
126+ /// Returns a reference to the inner [`StructVectorMut`] if `self` is of that variant.
127+ pub fn as_struct ( & self ) -> & StructVectorMut {
128+ if let VectorMut :: Struct ( v) = self {
129+ return v;
130+ }
131+ vortex_panic ! ( "Expected StructVectorMut, got {self:?}" ) ;
132+ }
133+
134+ /// Consumes `self` and returns the inner [`NullVectorMut`] if `self` is of that variant.
99135 pub fn into_null ( self ) -> NullVectorMut {
100136 if let VectorMut :: Null ( v) = self {
101137 return v;
102138 }
103139 vortex_panic ! ( "Expected NullVectorMut, got {self:?}" ) ;
104140 }
105141
106- /// Convert into BoolVectorMut, panicking if the type does not match .
142+ /// Consumes `self` and returns the inner [`BoolVectorMut`] if `self` is of that variant .
107143 pub fn into_bool ( self ) -> BoolVectorMut {
108144 if let VectorMut :: Bool ( v) = self {
109145 return v;
110146 }
111147 vortex_panic ! ( "Expected BoolVectorMut, got {self:?}" ) ;
112148 }
113149
114- /// Convert into PrimitiveVectorMut, panicking if the type does not match .
150+ /// Consumes `self` and returns the inner [`PrimitiveVectorMut`] if `self` is of that variant .
115151 pub fn into_primitive ( self ) -> PrimitiveVectorMut {
116152 if let VectorMut :: Primitive ( v) = self {
117153 return v;
118154 }
119155 vortex_panic ! ( "Expected PrimitiveVectorMut, got {self:?}" ) ;
120156 }
157+
158+ /// Consumes `self` and returns the inner [`StructVectorMut`] if `self` is of that variant.
159+ pub fn into_struct ( self ) -> StructVectorMut {
160+ if let VectorMut :: Struct ( v) = self {
161+ return v;
162+ }
163+ vortex_panic ! ( "Expected StructVectorMut, got {self:?}" ) ;
164+ }
121165}
122166
123167#[ cfg( test) ]
0 commit comments