@@ -41,7 +41,7 @@ pub trait Query: Send + Sized {
4141 /// Query protocol.
4242 type Protocol : crate :: prelude:: Protocol ;
4343
44- /// This methods corresponds to [`Queryable::query_iter`][query_iter].
44+ /// This method corresponds to [`Queryable::query_iter`][query_iter].
4545 ///
4646 /// [query_iter]: crate::prelude::Queryable::query_iter
4747 fn run < ' a , ' t : ' a , C > ( self , conn : C ) -> BoxFuture < ' a , QueryResult < ' a , ' t , Self :: Protocol > >
@@ -163,21 +163,21 @@ pub struct QueryWithParams<Q, P> {
163163
164164/// Helper, that constructs [`QueryWithParams`].
165165pub trait WithParams : Sized {
166- fn with < P > ( & self , params : P ) -> QueryWithParams < Self , P > ;
166+ fn with < P > ( self , params : P ) -> QueryWithParams < Self , P > ;
167167}
168168
169- impl < ' a , T : StatementLike + ? Sized > WithParams for & ' a T {
170- fn with < P > ( & self , params : P ) -> QueryWithParams < Self , P > {
169+ impl < T : StatementLike > WithParams for T {
170+ fn with < P > ( self , params : P ) -> QueryWithParams < Self , P > {
171171 QueryWithParams {
172172 query : self ,
173173 params,
174174 }
175175 }
176176}
177177
178- impl < Q , P > Query for QueryWithParams < & ' _ Q , P >
178+ impl < Q , P > Query for QueryWithParams < Q , P >
179179where
180- Q : StatementLike + ? Sized ,
180+ Q : StatementLike ,
181181 P : Into < Params > + Send ,
182182{
183183 type Protocol = BinaryProtocol ;
@@ -234,9 +234,9 @@ pub trait BatchQuery {
234234 C : ToConnection < ' a , ' t > + ' a ;
235235}
236236
237- impl < Q , I , P > BatchQuery for QueryWithParams < & ' _ Q , I >
237+ impl < Q , I , P > BatchQuery for QueryWithParams < Q , I >
238238where
239- Q : StatementLike + ? Sized ,
239+ Q : StatementLike ,
240240 I : IntoIterator < Item = P > + Send ,
241241 I :: IntoIter : Send ,
242242 P : Into < Params > + Send ,
@@ -327,8 +327,22 @@ mod tests {
327327
328328 #[ tokio:: test]
329329 async fn should_run_bin_query ( ) -> Result < ( ) > {
330- let query_static = "SELECT ?, ? UNION ALL SELECT ?, ?" ;
331- let query_string = String :: from ( query_static) ;
330+ macro_rules! query {
331+ ( @static ) => {
332+ "SELECT ?, ? UNION ALL SELECT ?, ?"
333+ } ;
334+ ( @string) => {
335+ String :: from( "SELECT ?, ? UNION ALL SELECT ?, ?" )
336+ } ;
337+ ( @boxed) => {
338+ query!( @string) . into_boxed_str( )
339+ } ;
340+ ( @arc) => {
341+ std:: sync:: Arc :: <str >:: from( query!( @boxed) )
342+ } ;
343+ }
344+
345+ let query_string = query ! ( @string) ;
332346 let params_static = ( "1" , "2" , "3" , "4" ) ;
333347 let params_string = (
334348 "1" . to_owned ( ) ,
@@ -339,7 +353,8 @@ mod tests {
339353
340354 macro_rules! test {
341355 ( $query: expr, $params: expr, $conn: expr) => { {
342- let mut result = $query. with( $params) . run( $conn) . await ?;
356+ let query = { $query. with( $params) } ;
357+ let mut result = query. run( $conn) . await ?;
343358 let result1: Vec <( u8 , u8 ) > = result. collect( ) . await ?;
344359 assert_eq!( result1, vec![ ( 1 , 2 ) , ( 3 , 4 ) ] ) ;
345360
@@ -371,23 +386,34 @@ mod tests {
371386 }
372387
373388 let mut conn = Conn :: new ( get_opts ( ) ) . await ?;
374- test ! ( query_static, params_static, & mut conn) ;
375- test ! ( query_string. as_str( ) , params_string. clone( ) , & mut conn) ;
389+ let statement = conn. prep ( query ! ( @static ) ) . await ?;
390+ test ! ( query!( @static ) , params_static, & mut conn) ;
391+ test ! ( query!( @string) , params_string. clone( ) , & mut conn) ;
392+ test ! ( query!( @boxed) , params_string. clone( ) , & mut conn) ;
393+ test ! ( query!( @arc) , params_string. clone( ) , & mut conn) ;
394+ test ! ( & query_string, params_string. clone( ) , & mut conn) ;
395+ test ! ( & statement, params_string. clone( ) , & mut conn) ;
396+ test ! ( statement. clone( ) , params_string. clone( ) , & mut conn) ;
376397
377398 let mut tx = conn. start_transaction ( Default :: default ( ) ) . await ?;
378- test ! ( query_static, params_string. clone( ) , & mut tx) ;
379- test ! ( query_string. as_str( ) , params_static, & mut tx) ;
399+ test ! ( query!( @static ) , params_string. clone( ) , & mut tx) ;
400+ test ! ( query!( @string) , params_static, & mut tx) ;
401+ test ! ( & query_string, params_static, & mut tx) ;
402+ test ! ( & statement, params_string. clone( ) , & mut tx) ;
403+ test ! ( statement. clone( ) , params_string. clone( ) , & mut tx) ;
380404 tx. rollback ( ) . await ?;
381405
382406 conn. disconnect ( ) . await ?;
383407
384408 let pool = Pool :: new ( get_opts ( ) ) ;
385- test ! ( query_static, params_static, & pool) ;
386- test ! ( query_string. as_str( ) , params_string. clone( ) , & pool) ;
409+ test ! ( query!( @static ) , params_static, & pool) ;
410+ test ! ( query!( @string) , params_string. clone( ) , & pool) ;
411+ test ! ( & query_string, params_string. clone( ) , & pool) ;
387412
388413 let mut tx = pool. start_transaction ( Default :: default ( ) ) . await ?;
389- test ! ( query_static, params_string. clone( ) , & mut tx) ;
390- test ! ( query_string. as_str( ) , params_static, & mut tx) ;
414+ test ! ( query!( @static ) , params_string. clone( ) , & mut tx) ;
415+ test ! ( query!( @string) , params_static, & mut tx) ;
416+ test ! ( & query_string, params_static, & mut tx) ;
391417 tx. rollback ( ) . await ?;
392418
393419 pool. disconnect ( ) . await ?;
0 commit comments