@@ -9,6 +9,14 @@ use sqlx_core::{
99
1010use crate :: { arguments:: ExaBuffer , Exasol } ;
1111
12+ /// Marker trait that limits arrays encoding to one dimensioanl arrays.
13+ ///
14+ /// Implementing it for some type `T` enables relevant [`Type`], [`Encode`] and [`Decode`] impls for
15+ /// [`Vec<T>`], [`&T`] (slices), [`[T;N]`] (arrays), [`ExaIter`], etc.
16+ pub trait ExaHasArrayType : Type < Exasol > { }
17+
18+ impl < T > ExaHasArrayType for & T where T : ExaHasArrayType { }
19+
1220/// Adapter allowing any iterator of encodable values to be treated and passed as a one dimensional
1321/// parameter array for a column to Exasol in a single query invocation. Multi dimensional arrays
1422/// are not supported. The adapter is needed because [`Encode`] is still a foreign trait and thus
@@ -31,53 +39,26 @@ use crate::{arguments::ExaBuffer, Exasol};
3139#[ repr( transparent) ]
3240pub struct ExaIter < I , T > {
3341 into_iter : I ,
34- data_lifetime : PhantomData < fn ( ) -> T > ,
42+ _marker : PhantomData < fn ( ) -> T > ,
3543}
3644
3745impl < I , T > ExaIter < I , T >
3846where
3947 I : IntoIterator < Item = T > + Clone ,
40- T : for < ' q > Encode < ' q , Exasol > + Type < Exasol > + Copy ,
48+ T : for < ' q > Encode < ' q , Exasol > + ExaHasArrayType + Copy ,
4149{
4250 pub fn new ( into_iter : I ) -> Self {
4351 Self {
4452 into_iter,
45- data_lifetime : PhantomData ,
53+ _marker : PhantomData ,
4654 }
4755 }
4856}
4957
5058impl < I , T > Type < Exasol > for ExaIter < I , T >
5159where
5260 I : IntoIterator < Item = T > + Clone ,
53- T : Type < Exasol > + Copy ,
54- {
55- fn type_info ( ) -> <Exasol as Database >:: TypeInfo {
56- T :: type_info ( )
57- }
58- }
59-
60- impl < T > Type < Exasol > for [ T ]
61- where
62- T : Type < Exasol > ,
63- {
64- fn type_info ( ) -> <Exasol as Database >:: TypeInfo {
65- T :: type_info ( )
66- }
67- }
68-
69- impl < T , const N : usize > Type < Exasol > for [ T ; N ]
70- where
71- T : Type < Exasol > ,
72- {
73- fn type_info ( ) -> <Exasol as Database >:: TypeInfo {
74- T :: type_info ( )
75- }
76- }
77-
78- impl < T > Type < Exasol > for Vec < T >
79- where
80- T : Type < Exasol > ,
61+ T : ExaHasArrayType + Copy ,
8162{
8263 fn type_info ( ) -> <Exasol as Database >:: TypeInfo {
8364 T :: type_info ( )
@@ -104,11 +85,27 @@ where
10485 }
10586}
10687
88+ macro_rules! forward_arr_type_impl {
89+ ( $for_type: ty, $( $generics: tt) * ) => {
90+ impl <T , $( $generics) * > Type <Exasol > for $for_type
91+ where
92+ T : ExaHasArrayType ,
93+ {
94+ fn type_info( ) -> <Exasol as Database >:: TypeInfo {
95+ T :: type_info( )
96+ }
97+ }
98+ } ;
99+ ( $for_type: ty) => {
100+ forward_arr_type_impl!( $for_type, ) ;
101+ }
102+ }
103+
107104macro_rules! forward_arr_encode_impl {
108105 ( $for_type: ty, $( $generics: tt) * ) => {
109106 impl <T , $( $generics) * > Encode <' _, Exasol > for $for_type
110107 where
111- for <' q> T : Encode <' q, Exasol > + Type < Exasol > ,
108+ for <' q> T : Encode <' q, Exasol > + ExaHasArrayType ,
112109 {
113110 fn encode_by_ref( & self , buf: & mut ExaBuffer ) -> Result <IsNull , BoxDynError > {
114111 ExaIter :: new( AsRef :: <[ T ] >:: as_ref( & self ) ) . encode_by_ref( buf)
@@ -124,6 +121,10 @@ macro_rules! forward_arr_encode_impl {
124121 }
125122}
126123
124+ forward_arr_type_impl ! ( [ T ] ) ;
125+ forward_arr_type_impl ! ( [ T ; N ] , const N : usize ) ;
126+ forward_arr_type_impl ! ( Vec <T >) ;
127+
127128forward_arr_encode_impl ! ( & [ T ] ) ;
128129forward_arr_encode_impl ! ( [ T ; N ] , const N : usize ) ;
129130forward_arr_encode_impl ! ( Vec <T >) ;
0 commit comments