@@ -6,6 +6,7 @@ use futures_core::future::BoxFuture;
6
6
use log:: LevelFilter ;
7
7
use std:: borrow:: Cow ;
8
8
use std:: fmt:: Debug ;
9
+ use std:: future:: Future ;
9
10
use std:: str:: FromStr ;
10
11
use std:: time:: Duration ;
11
12
use url:: Url ;
@@ -32,23 +33,23 @@ pub trait Connection: Send {
32
33
///
33
34
/// Therefore it is recommended to call `.close()` on a connection when you are done using it
34
35
/// 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 ;
36
37
37
38
/// Immediately close the connection without sending a graceful shutdown.
38
39
///
39
40
/// This should still at least send a TCP `FIN` frame to let the server know we're dying.
40
41
#[ doc( hidden) ]
41
- fn close_hard ( self ) -> BoxFuture < ' static , Result < ( ) , Error > > ;
42
+ fn close_hard ( self ) -> impl Future < Output = Result < ( ) , Error > > + Send + ' static ;
42
43
43
44
/// 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 + ' _ ;
45
46
46
47
/// Begin a new transaction or establish a savepoint within the active transaction.
47
48
///
48
49
/// 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 + ' _ ;
52
53
53
54
/// Begin a new transaction with a custom statement.
54
55
///
@@ -59,7 +60,7 @@ pub trait Connection: Send {
59
60
fn begin_with (
60
61
& mut self ,
61
62
statement : impl Into < Cow < ' static , str > > ,
62
- ) -> BoxFuture < ' _ , Result < Transaction < ' _ , Self :: Database > , Error > >
63
+ ) -> impl Future < Output = Result < Transaction < ' _ , Self :: Database > , Error > > + Send + ' _
63
64
where
64
65
Self : Sized ,
65
66
{
@@ -94,7 +95,10 @@ pub trait Connection: Send {
94
95
/// })).await
95
96
/// # }
96
97
/// ```
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
98
102
where
99
103
for < ' c > F : FnOnce ( & ' c mut Transaction < ' _ , Self :: Database > ) -> BoxFuture < ' c , Result < R , E > >
100
104
+ ' a
@@ -104,7 +108,7 @@ pub trait Connection: Send {
104
108
R : Send ,
105
109
E : From < Error > + Send ,
106
110
{
107
- Box :: pin ( async move {
111
+ async move {
108
112
let mut transaction = self . begin ( ) . await ?;
109
113
let ret = callback ( & mut transaction) . await ;
110
114
@@ -120,7 +124,7 @@ pub trait Connection: Send {
120
124
Err ( err)
121
125
}
122
126
}
123
- } )
127
+ }
124
128
}
125
129
126
130
/// The number of statements currently cached in the connection.
@@ -133,11 +137,11 @@ pub trait Connection: Send {
133
137
134
138
/// Removes all statements from the cache, closing them on the server if
135
139
/// needed.
136
- fn clear_cached_statements ( & mut self ) -> BoxFuture < ' _ , Result < ( ) , Error > >
140
+ fn clear_cached_statements ( & mut self ) -> impl Future < Output = Result < ( ) , Error > > + Send + ' _
137
141
where
138
142
Self :: Database : HasStatementCache ,
139
143
{
140
- Box :: pin ( async move { Ok ( ( ) ) } )
144
+ async move { Ok ( ( ) ) }
141
145
}
142
146
143
147
/// Restore any buffers in the connection to their default capacity, if possible.
@@ -155,7 +159,7 @@ pub trait Connection: Send {
155
159
fn shrink_buffers ( & mut self ) ;
156
160
157
161
#[ doc( hidden) ]
158
- fn flush ( & mut self ) -> BoxFuture < ' _ , Result < ( ) , Error > > ;
162
+ fn flush ( & mut self ) -> impl Future < Output = Result < ( ) , Error > > + Send + ' _ ;
159
163
160
164
#[ doc( hidden) ]
161
165
fn should_flush ( & self ) -> bool ;
@@ -165,17 +169,19 @@ pub trait Connection: Send {
165
169
/// A value of [`Options`][Self::Options] is parsed from the provided connection string. This parsing
166
170
/// is database-specific.
167
171
#[ inline]
168
- fn connect ( url : & str ) -> BoxFuture < ' static , Result < Self , Error > >
172
+ fn connect ( url : & str ) -> impl Future < Output = Result < Self , Error > > + Send + ' static
169
173
where
170
174
Self : Sized ,
171
175
{
172
176
let options = url. parse ( ) ;
173
177
174
- Box :: pin ( async move { Self :: connect_with ( & options?) . await } )
178
+ async move { Self :: connect_with ( & options?) . await }
175
179
}
176
180
177
181
/// 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 + ' _
179
185
where
180
186
Self : Sized ,
181
187
{
@@ -247,7 +253,7 @@ pub trait ConnectOptions: 'static + Send + Sync + FromStr<Err = Error> + Debug +
247
253
}
248
254
249
255
/// 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 + ' _
251
257
where
252
258
Self :: Connection : Sized ;
253
259
0 commit comments