@@ -6,6 +6,7 @@ use futures_core::future::BoxFuture;
66use log:: LevelFilter ;
77use std:: borrow:: Cow ;
88use std:: fmt:: Debug ;
9+ use std:: future:: Future ;
910use std:: str:: FromStr ;
1011use std:: time:: Duration ;
1112use url:: Url ;
@@ -32,23 +33,23 @@ pub trait Connection: Send {
3233 ///
3334 /// Therefore it is recommended to call `.close()` on a connection when you are done using it
3435 /// and to `.await` the result to ensure the termination message is sent.
35- fn close ( self ) -> BoxFuture < ' static , Result < ( ) , Error > > ;
36+ fn close ( self ) -> impl Future < Output = Result < ( ) , Error > > + Send + ' static ;
3637
3738 /// Immediately close the connection without sending a graceful shutdown.
3839 ///
3940 /// This should still at least send a TCP `FIN` frame to let the server know we're dying.
4041 #[ doc( hidden) ]
41- fn close_hard ( self ) -> BoxFuture < ' static , Result < ( ) , Error > > ;
42+ fn close_hard ( self ) -> impl Future < Output = Result < ( ) , Error > > + Send + ' static ;
4243
4344 /// Checks if a connection to the database is still valid.
44- fn ping ( & mut self ) -> BoxFuture < ' _ , Result < ( ) , Error > > ;
45+ fn ping ( & mut self ) -> impl Future < Output = Result < ( ) , Error > > + Send + ' _ ;
4546
4647 /// Begin a new transaction or establish a savepoint within the active transaction.
4748 ///
4849 /// Returns a [`Transaction`] for controlling and tracking the new transaction.
49- fn begin ( & mut self ) -> BoxFuture < ' _ , Result < Transaction < ' _ , Self :: Database > , Error > >
50- where
51- Self : Sized ;
50+ fn begin (
51+ & mut self ,
52+ ) -> impl Future < Output = Result < Transaction < ' _ , Self :: Database > , Error > > + Send + ' _ ;
5253
5354 /// Begin a new transaction with a custom statement.
5455 ///
@@ -59,7 +60,7 @@ pub trait Connection: Send {
5960 fn begin_with (
6061 & mut self ,
6162 statement : impl Into < Cow < ' static , str > > ,
62- ) -> BoxFuture < ' _ , Result < Transaction < ' _ , Self :: Database > , Error > >
63+ ) -> impl Future < Output = Result < Transaction < ' _ , Self :: Database > , Error > > + Send + ' _
6364 where
6465 Self : Sized ,
6566 {
@@ -94,7 +95,10 @@ pub trait Connection: Send {
9495 /// })).await
9596 /// # }
9697 /// ```
97- fn transaction < ' a , F , R , E > ( & ' a mut self , callback : F ) -> BoxFuture < ' a , Result < R , E > >
98+ fn transaction < ' a , F , R , E > (
99+ & ' a mut self ,
100+ callback : F ,
101+ ) -> impl Future < Output = Result < R , E > > + Send + ' a
98102 where
99103 for < ' c > F : FnOnce ( & ' c mut Transaction < ' _ , Self :: Database > ) -> BoxFuture < ' c , Result < R , E > >
100104 + ' a
@@ -104,7 +108,7 @@ pub trait Connection: Send {
104108 R : Send ,
105109 E : From < Error > + Send ,
106110 {
107- Box :: pin ( async move {
111+ async move {
108112 let mut transaction = self . begin ( ) . await ?;
109113 let ret = callback ( & mut transaction) . await ;
110114
@@ -120,7 +124,7 @@ pub trait Connection: Send {
120124 Err ( err)
121125 }
122126 }
123- } )
127+ }
124128 }
125129
126130 /// The number of statements currently cached in the connection.
@@ -133,11 +137,11 @@ pub trait Connection: Send {
133137
134138 /// Removes all statements from the cache, closing them on the server if
135139 /// needed.
136- fn clear_cached_statements ( & mut self ) -> BoxFuture < ' _ , Result < ( ) , Error > >
140+ fn clear_cached_statements ( & mut self ) -> impl Future < Output = Result < ( ) , Error > > + Send + ' _
137141 where
138142 Self :: Database : HasStatementCache ,
139143 {
140- Box :: pin ( async move { Ok ( ( ) ) } )
144+ async move { Ok ( ( ) ) }
141145 }
142146
143147 /// Restore any buffers in the connection to their default capacity, if possible.
@@ -155,7 +159,7 @@ pub trait Connection: Send {
155159 fn shrink_buffers ( & mut self ) ;
156160
157161 #[ doc( hidden) ]
158- fn flush ( & mut self ) -> BoxFuture < ' _ , Result < ( ) , Error > > ;
162+ fn flush ( & mut self ) -> impl Future < Output = Result < ( ) , Error > > + Send + ' _ ;
159163
160164 #[ doc( hidden) ]
161165 fn should_flush ( & self ) -> bool ;
@@ -165,17 +169,19 @@ pub trait Connection: Send {
165169 /// A value of [`Options`][Self::Options] is parsed from the provided connection string. This parsing
166170 /// is database-specific.
167171 #[ inline]
168- fn connect ( url : & str ) -> BoxFuture < ' static , Result < Self , Error > >
172+ fn connect ( url : & str ) -> impl Future < Output = Result < Self , Error > > + Send + ' static
169173 where
170174 Self : Sized ,
171175 {
172176 let options = url. parse ( ) ;
173177
174- Box :: pin ( async move { Self :: connect_with ( & options?) . await } )
178+ async move { Self :: connect_with ( & options?) . await }
175179 }
176180
177181 /// Establish a new database connection with the provided options.
178- fn connect_with ( options : & Self :: Options ) -> BoxFuture < ' _ , Result < Self , Error > >
182+ fn connect_with (
183+ options : & Self :: Options ,
184+ ) -> impl Future < Output = Result < Self , Error > > + Send + ' _
179185 where
180186 Self : Sized ,
181187 {
@@ -247,7 +253,7 @@ pub trait ConnectOptions: 'static + Send + Sync + FromStr<Err = Error> + Debug +
247253 }
248254
249255 /// Establish a new database connection with the options specified by `self`.
250- fn connect ( & self ) -> BoxFuture < ' _ , Result < Self :: Connection , Error > >
256+ fn connect ( & self ) -> impl Future < Output = Result < Self :: Connection , Error > > + Send + ' _
251257 where
252258 Self :: Connection : Sized ;
253259
0 commit comments