@@ -165,23 +165,35 @@ impl Client {
165165 PrepareFuture :: new ( self . clone ( ) , pending, name)
166166 }
167167
168- pub fn execute ( & self , statement : & Statement , params : & [ & dyn ToSql ] ) -> ExecuteFuture {
168+ pub fn execute < ' a , I > ( & self , statement : & Statement , params : I ) -> ExecuteFuture
169+ where
170+ I : IntoIterator < Item = & ' a dyn ToSql > ,
171+ I :: IntoIter : ExactSizeIterator ,
172+ {
169173 let pending = PendingRequest (
170174 self . excecute_message ( statement, params)
171175 . map ( |m| ( RequestMessages :: Single ( m) , self . 0 . idle . guard ( ) ) ) ,
172176 ) ;
173177 ExecuteFuture :: new ( self . clone ( ) , pending, statement. clone ( ) )
174178 }
175179
176- pub fn query ( & self , statement : & Statement , params : & [ & dyn ToSql ] ) -> QueryStream < Statement > {
180+ pub fn query < ' a , I > ( & self , statement : & Statement , params : I ) -> QueryStream < Statement >
181+ where
182+ I : IntoIterator < Item = & ' a dyn ToSql > ,
183+ I :: IntoIter : ExactSizeIterator ,
184+ {
177185 let pending = PendingRequest (
178186 self . excecute_message ( statement, params)
179187 . map ( |m| ( RequestMessages :: Single ( m) , self . 0 . idle . guard ( ) ) ) ,
180188 ) ;
181189 QueryStream :: new ( self . clone ( ) , pending, statement. clone ( ) )
182190 }
183191
184- pub fn bind ( & self , statement : & Statement , name : String , params : & [ & dyn ToSql ] ) -> BindFuture {
192+ pub fn bind < ' a , I > ( & self , statement : & Statement , name : String , params : I ) -> BindFuture
193+ where
194+ I : IntoIterator < Item = & ' a dyn ToSql > ,
195+ I :: IntoIter : ExactSizeIterator ,
196+ {
185197 let mut buf = self . bind_message ( statement, & name, params) ;
186198 if let Ok ( ref mut buf) = buf {
187199 frontend:: sync ( buf) ;
@@ -204,17 +216,14 @@ impl Client {
204216 QueryStream :: new ( self . clone ( ) , pending, portal. clone ( ) )
205217 }
206218
207- pub fn copy_in < S > (
208- & self ,
209- statement : & Statement ,
210- params : & [ & dyn ToSql ] ,
211- stream : S ,
212- ) -> CopyInFuture < S >
219+ pub fn copy_in < ' a , S , I > ( & self , statement : & Statement , params : I , stream : S ) -> CopyInFuture < S >
213220 where
214221 S : Stream ,
215222 S :: Item : IntoBuf ,
216223 <S :: Item as IntoBuf >:: Buf : ' static + Send ,
217224 S :: Error : Into < Box < dyn StdError + Sync + Send > > ,
225+ I : IntoIterator < Item = & ' a dyn ToSql > ,
226+ I :: IntoIter : ExactSizeIterator ,
218227 {
219228 let ( mut sender, receiver) = mpsc:: channel ( 1 ) ;
220229 let pending = PendingRequest ( self . excecute_message ( statement, params) . map ( |data| {
@@ -233,7 +242,11 @@ impl Client {
233242 CopyInFuture :: new ( self . clone ( ) , pending, statement. clone ( ) , stream, sender)
234243 }
235244
236- pub fn copy_out ( & self , statement : & Statement , params : & [ & dyn ToSql ] ) -> CopyOutStream {
245+ pub fn copy_out < ' a , I > ( & self , statement : & Statement , params : I ) -> CopyOutStream
246+ where
247+ I : IntoIterator < Item = & ' a dyn ToSql > ,
248+ I :: IntoIter : ExactSizeIterator ,
249+ {
237250 let pending = PendingRequest (
238251 self . excecute_message ( statement, params)
239252 . map ( |m| ( RequestMessages :: Single ( m) , self . 0 . idle . guard ( ) ) ) ,
@@ -289,12 +302,18 @@ impl Client {
289302 } ) ;
290303 }
291304
292- fn bind_message (
305+ fn bind_message < ' a , I > (
293306 & self ,
294307 statement : & Statement ,
295308 name : & str ,
296- params : & [ & dyn ToSql ] ,
297- ) -> Result < Vec < u8 > , Error > {
309+ params : I ,
310+ ) -> Result < Vec < u8 > , Error >
311+ where
312+ I : IntoIterator < Item = & ' a dyn ToSql > ,
313+ I :: IntoIter : ExactSizeIterator ,
314+ {
315+ let params = params. into_iter ( ) ;
316+
298317 assert ! (
299318 statement. params( ) . len( ) == params. len( ) ,
300319 "expected {} parameters but got {}" ,
@@ -308,7 +327,7 @@ impl Client {
308327 name,
309328 statement. name ( ) ,
310329 Some ( 1 ) ,
311- params. iter ( ) . zip ( statement. params ( ) ) . enumerate ( ) ,
330+ params. zip ( statement. params ( ) ) . enumerate ( ) ,
312331 |( idx, ( param, ty) ) , buf| match param. to_sql_checked ( ty, buf) {
313332 Ok ( IsNull :: No ) => Ok ( postgres_protocol:: IsNull :: No ) ,
314333 Ok ( IsNull :: Yes ) => Ok ( postgres_protocol:: IsNull :: Yes ) ,
@@ -327,11 +346,15 @@ impl Client {
327346 }
328347 }
329348
330- fn excecute_message (
349+ fn excecute_message < ' a , I > (
331350 & self ,
332351 statement : & Statement ,
333- params : & [ & dyn ToSql ] ,
334- ) -> Result < FrontendMessage , Error > {
352+ params : I ,
353+ ) -> Result < FrontendMessage , Error >
354+ where
355+ I : IntoIterator < Item = & ' a dyn ToSql > ,
356+ I :: IntoIter : ExactSizeIterator ,
357+ {
335358 let mut buf = self . bind_message ( statement, "" , params) ?;
336359 frontend:: execute ( "" , 0 , & mut buf) . map_err ( Error :: parse) ?;
337360 frontend:: sync ( & mut buf) ;
0 commit comments