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
use odbc_sys::{Date, Time, Timestamp};
use super::{AnyColumnView, AnyColumnViewMut, BufferKind, NullableSlice, NullableSliceMut};
use crate::Bit;
pub trait Item: Sized + Copy {
const BUFFER_KIND: BufferKind;
fn as_slice(variant: AnyColumnView<'_>) -> Option<&[Self]>;
fn as_nullable_slice(variant: AnyColumnView<'_>) -> Option<NullableSlice<Self>>;
fn as_slice_mut(variant: AnyColumnViewMut<'_>) -> Option<&mut [Self]>;
fn as_nullable_slice_mut(variant: AnyColumnViewMut<'_>) -> Option<NullableSliceMut<Self>>;
}
macro_rules! impl_item {
($t:ident, $plain:ident, $null:ident) => {
impl Item for $t {
const BUFFER_KIND: BufferKind = BufferKind::$plain;
fn as_slice(variant: AnyColumnView<'_>) -> Option<&[Self]> {
match variant {
AnyColumnView::$plain(vals) => Some(vals),
_ => None,
}
}
fn as_nullable_slice(variant: AnyColumnView<'_>) -> Option<NullableSlice<Self>> {
match variant {
AnyColumnView::$null(vals) => Some(vals),
_ => None,
}
}
fn as_slice_mut(variant: AnyColumnViewMut<'_>) -> Option<&mut [Self]> {
match variant {
AnyColumnViewMut::$plain(vals) => Some(vals),
_ => None,
}
}
fn as_nullable_slice_mut(
variant: AnyColumnViewMut<'_>,
) -> Option<NullableSliceMut<Self>> {
match variant {
AnyColumnViewMut::$null(vals) => Some(vals),
_ => None,
}
}
}
};
}
impl_item!(f64, F64, NullableF64);
impl_item!(f32, F32, NullableF32);
impl_item!(u8, U8, NullableU8);
impl_item!(i8, I8, NullableI8);
impl_item!(i16, I16, NullableI16);
impl_item!(i32, I32, NullableI32);
impl_item!(i64, I64, NullableI64);
impl_item!(Date, Date, NullableDate);
impl_item!(Bit, Bit, NullableBit);
impl_item!(Time, Time, NullableTime);
impl_item!(Timestamp, Timestamp, NullableTimestamp);