@@ -165,23 +165,35 @@ impl Client {
165
165
PrepareFuture :: new ( self . clone ( ) , pending, name)
166
166
}
167
167
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
+ {
169
173
let pending = PendingRequest (
170
174
self . excecute_message ( statement, params)
171
175
. map ( |m| ( RequestMessages :: Single ( m) , self . 0 . idle . guard ( ) ) ) ,
172
176
) ;
173
177
ExecuteFuture :: new ( self . clone ( ) , pending, statement. clone ( ) )
174
178
}
175
179
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
+ {
177
185
let pending = PendingRequest (
178
186
self . excecute_message ( statement, params)
179
187
. map ( |m| ( RequestMessages :: Single ( m) , self . 0 . idle . guard ( ) ) ) ,
180
188
) ;
181
189
QueryStream :: new ( self . clone ( ) , pending, statement. clone ( ) )
182
190
}
183
191
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
+ {
185
197
let mut buf = self . bind_message ( statement, & name, params) ;
186
198
if let Ok ( ref mut buf) = buf {
187
199
frontend:: sync ( buf) ;
@@ -204,17 +216,14 @@ impl Client {
204
216
QueryStream :: new ( self . clone ( ) , pending, portal. clone ( ) )
205
217
}
206
218
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 >
213
220
where
214
221
S : Stream ,
215
222
S :: Item : IntoBuf ,
216
223
<S :: Item as IntoBuf >:: Buf : ' static + Send ,
217
224
S :: Error : Into < Box < dyn StdError + Sync + Send > > ,
225
+ I : IntoIterator < Item = & ' a dyn ToSql > ,
226
+ I :: IntoIter : ExactSizeIterator ,
218
227
{
219
228
let ( mut sender, receiver) = mpsc:: channel ( 1 ) ;
220
229
let pending = PendingRequest ( self . excecute_message ( statement, params) . map ( |data| {
@@ -233,7 +242,11 @@ impl Client {
233
242
CopyInFuture :: new ( self . clone ( ) , pending, statement. clone ( ) , stream, sender)
234
243
}
235
244
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
+ {
237
250
let pending = PendingRequest (
238
251
self . excecute_message ( statement, params)
239
252
. map ( |m| ( RequestMessages :: Single ( m) , self . 0 . idle . guard ( ) ) ) ,
@@ -289,12 +302,18 @@ impl Client {
289
302
} ) ;
290
303
}
291
304
292
- fn bind_message (
305
+ fn bind_message < ' a , I > (
293
306
& self ,
294
307
statement : & Statement ,
295
308
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
+
298
317
assert ! (
299
318
statement. params( ) . len( ) == params. len( ) ,
300
319
"expected {} parameters but got {}" ,
@@ -308,7 +327,7 @@ impl Client {
308
327
name,
309
328
statement. name ( ) ,
310
329
Some ( 1 ) ,
311
- params. iter ( ) . zip ( statement. params ( ) ) . enumerate ( ) ,
330
+ params. zip ( statement. params ( ) ) . enumerate ( ) ,
312
331
|( idx, ( param, ty) ) , buf| match param. to_sql_checked ( ty, buf) {
313
332
Ok ( IsNull :: No ) => Ok ( postgres_protocol:: IsNull :: No ) ,
314
333
Ok ( IsNull :: Yes ) => Ok ( postgres_protocol:: IsNull :: Yes ) ,
@@ -327,11 +346,15 @@ impl Client {
327
346
}
328
347
}
329
348
330
- fn excecute_message (
349
+ fn excecute_message < ' a , I > (
331
350
& self ,
332
351
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
+ {
335
358
let mut buf = self . bind_message ( statement, "" , params) ?;
336
359
frontend:: execute ( "" , 0 , & mut buf) . map_err ( Error :: parse) ?;
337
360
frontend:: sync ( & mut buf) ;
0 commit comments