@@ -44,6 +44,8 @@ pub enum Datum<'a> {
4444 #[ display( "{0}" ) ]
4545 Bool ( bool ) ,
4646 #[ display( "{0}" ) ]
47+ Int8 ( i8 ) ,
48+ #[ display( "{0}" ) ]
4749 Int16 ( i16 ) ,
4850 #[ display( "{0}" ) ]
4951 Int32 ( i32 ) ,
@@ -78,6 +80,13 @@ impl Datum<'_> {
7880 _ => panic ! ( "not a string: {self:?}" ) ,
7981 }
8082 }
83+
84+ pub fn as_blob ( & self ) -> & [ u8 ] {
85+ match self {
86+ Self :: Blob ( blob) => blob. as_ref ( ) ,
87+ _ => panic ! ( "not a blob: {self:?}" ) ,
88+ }
89+ }
8190}
8291
8392// ----------- implement from
@@ -95,6 +104,20 @@ impl<'a> From<i64> for Datum<'a> {
95104 }
96105}
97106
107+ impl < ' a > From < i8 > for Datum < ' a > {
108+ #[ inline]
109+ fn from ( i : i8 ) -> Datum < ' a > {
110+ Datum :: Int8 ( i)
111+ }
112+ }
113+
114+ impl < ' a > From < i16 > for Datum < ' a > {
115+ #[ inline]
116+ fn from ( i : i16 ) -> Datum < ' a > {
117+ Datum :: Int16 ( i)
118+ }
119+ }
120+
98121impl < ' a > From < & ' a str > for Datum < ' a > {
99122 #[ inline]
100123 fn from ( s : & ' a str ) -> Datum < ' a > {
@@ -134,6 +157,18 @@ impl TryFrom<&Datum<'_>> for i32 {
134157 }
135158}
136159
160+ impl TryFrom < & Datum < ' _ > > for i16 {
161+ type Error = ( ) ;
162+
163+ #[ inline]
164+ fn try_from ( from : & Datum ) -> std:: result:: Result < Self , Self :: Error > {
165+ match from {
166+ Datum :: Int16 ( i) => Ok ( * i) ,
167+ _ => Err ( ( ) ) ,
168+ }
169+ }
170+ }
171+
137172impl TryFrom < & Datum < ' _ > > for i64 {
138173 type Error = ( ) ;
139174
@@ -146,6 +181,42 @@ impl TryFrom<&Datum<'_>> for i64 {
146181 }
147182}
148183
184+ impl TryFrom < & Datum < ' _ > > for f32 {
185+ type Error = ( ) ;
186+
187+ #[ inline]
188+ fn try_from ( from : & Datum ) -> std:: result:: Result < Self , Self :: Error > {
189+ match from {
190+ Datum :: Float32 ( f) => Ok ( f. into_inner ( ) ) ,
191+ _ => Err ( ( ) ) ,
192+ }
193+ }
194+ }
195+
196+ impl TryFrom < & Datum < ' _ > > for f64 {
197+ type Error = ( ) ;
198+
199+ #[ inline]
200+ fn try_from ( from : & Datum ) -> std:: result:: Result < Self , Self :: Error > {
201+ match from {
202+ Datum :: Float64 ( f) => Ok ( f. into_inner ( ) ) ,
203+ _ => Err ( ( ) ) ,
204+ }
205+ }
206+ }
207+
208+ impl TryFrom < & Datum < ' _ > > for bool {
209+ type Error = ( ) ;
210+
211+ #[ inline]
212+ fn try_from ( from : & Datum ) -> std:: result:: Result < Self , Self :: Error > {
213+ match from {
214+ Datum :: Bool ( b) => Ok ( * b) ,
215+ _ => Err ( ( ) ) ,
216+ }
217+ }
218+ }
219+
149220impl < ' a > TryFrom < & Datum < ' a > > for & ' a str {
150221 type Error = ( ) ;
151222
@@ -158,6 +229,25 @@ impl<'a> TryFrom<&Datum<'a>> for &'a str {
158229 }
159230}
160231
232+ impl TryFrom < & Datum < ' _ > > for i8 {
233+ type Error = ( ) ;
234+
235+ #[ inline]
236+ fn try_from ( from : & Datum ) -> std:: result:: Result < Self , Self :: Error > {
237+ match from {
238+ Datum :: Int8 ( i) => Ok ( * i) ,
239+ _ => Err ( ( ) ) ,
240+ }
241+ }
242+ }
243+
244+ impl < ' a > From < bool > for Datum < ' a > {
245+ #[ inline]
246+ fn from ( b : bool ) -> Datum < ' a > {
247+ Datum :: Bool ( b)
248+ }
249+ }
250+
161251pub trait ToArrow {
162252 fn append_to ( & self , builder : & mut dyn ArrayBuilder ) -> Result < ( ) > ;
163253}
@@ -184,6 +274,7 @@ impl Datum<'_> {
184274
185275 match self {
186276 Datum :: Null => {
277+ append_null_to_arrow ! ( Int8Builder ) ;
187278 append_null_to_arrow ! ( BooleanBuilder ) ;
188279 append_null_to_arrow ! ( Int16Builder ) ;
189280 append_null_to_arrow ! ( Int32Builder ) ;
@@ -194,6 +285,7 @@ impl Datum<'_> {
194285 append_null_to_arrow ! ( BinaryBuilder ) ;
195286 }
196287 Datum :: Bool ( v) => append_value_to_arrow ! ( BooleanBuilder , * v) ,
288+ Datum :: Int8 ( v) => append_value_to_arrow ! ( Int8Builder , * v) ,
197289 Datum :: Int16 ( v) => append_value_to_arrow ! ( Int16Builder , * v) ,
198290 Datum :: Int32 ( v) => append_value_to_arrow ! ( Int32Builder , * v) ,
199291 Datum :: Int64 ( v) => append_value_to_arrow ! ( Int64Builder , * v) ,
0 commit comments