@@ -12,36 +12,32 @@ use crate::{arguments::ExaBuffer, Exasol};
1212/// Adapter allowing any iterator of encodable values to be treated and passed as a one dimensional
1313/// parameter array for a column to Exasol in a single query invocation. Multi dimensional arrays
1414/// are not supported. The adapter is needed because [`Encode`] is still a foreign trait and thus
15- /// cannot be implemented in a generic manner.
15+ /// cannot be implemented in a generic manner to all types implementing [`IntoIterator`] .
1616///
1717/// Note that the [`Encode`] trait requires the ability to encode by reference, thus the adapter
18- /// takes a reference that implements [`IntoIterator`]. But since iteration requires mutability,
18+ /// takes a type that implements [`IntoIterator`]. But since iteration requires mutability,
1919/// the adaptar also requires [`Clone`]. The adapter definition should steer it towards being used
2020/// with cheaply clonable iterators since it expects the iteration elements to be references.
21+ /// However, care should still be taken so as not to clone expensive [`IntoIterator`] types.
2122///
2223/// ```rust
2324/// # use sqlx_exasol_impl as sqlx_exasol;
2425/// use sqlx_exasol::types::ExaIter;
2526///
2627/// let vector = vec![1, 2, 3];
27- /// let borrowed_iter = ExaIter::new(vector.as_slice( ));
28+ /// let borrowed_iter = ExaIter::new(vector.iter().filter(|v| **v % 2 == 0 ));
2829/// ```
2930#[ derive( Debug ) ]
3031#[ repr( transparent) ]
31- pub struct ExaIter < ' i , I , T >
32- where
33- I : IntoIterator < Item = & ' i T > + Clone ,
34- T : ' i ,
35- {
32+ pub struct ExaIter < I , T > {
3633 into_iter : I ,
37- data_lifetime : PhantomData < & ' i ( ) > ,
34+ data_lifetime : PhantomData < fn ( ) -> T > ,
3835}
3936
40- impl < ' i , ' q , I , T > ExaIter < ' i , I , T >
37+ impl < I , T > ExaIter < I , T >
4138where
42- I : IntoIterator < Item = & ' i T > + Clone ,
43- T : ' i + Type < Exasol > + Encode < ' q , Exasol > ,
44- ' i : ' q ,
39+ I : IntoIterator < Item = T > + Clone ,
40+ T : for < ' q > Encode < ' q , Exasol > + Type < Exasol > + Copy ,
4541{
4642 pub fn new ( into_iter : I ) -> Self {
4743 Self {
@@ -51,21 +47,20 @@ where
5147 }
5248}
5349
54- impl < ' i , I , T > Type < Exasol > for ExaIter < ' i , I , T >
50+ impl < I , T > Type < Exasol > for ExaIter < I , T >
5551where
56- I : IntoIterator < Item = & ' i T > + Clone ,
57- T : ' i + Type < Exasol > ,
52+ I : IntoIterator < Item = T > + Clone ,
53+ T : Type < Exasol > + Copy ,
5854{
5955 fn type_info ( ) -> <Exasol as Database >:: TypeInfo {
6056 <I as IntoIterator >:: Item :: type_info ( )
6157 }
6258}
6359
64- impl < ' i , ' q , I , T > Encode < ' q , Exasol > for ExaIter < ' i , I , T >
60+ impl < I , T > Encode < ' _ , Exasol > for ExaIter < I , T >
6561where
66- I : IntoIterator < Item = & ' i T > + Clone ,
67- T : ' i + Encode < ' q , Exasol > ,
68- ' i : ' q ,
62+ I : IntoIterator < Item = T > + Clone ,
63+ T : for < ' q > Encode < ' q , Exasol > + Copy ,
6964{
7065 fn encode_by_ref ( & self , buf : & mut ExaBuffer ) -> Result < IsNull , BoxDynError > {
7166 buf. append_iter ( self . into_iter . clone ( ) ) ?;
0 commit comments