File tree Expand file tree Collapse file tree 6 files changed +47
-16
lines changed
Expand file tree Collapse file tree 6 files changed +47
-16
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,6 @@ async fn main() -> monzo::Result<()> {
2323 . transactions ( account_id)
2424 . since ( Utc :: now ( ) - Duration :: try_days ( args. days ) . unwrap ( ) )
2525 . limit ( args. limit )
26- . send ( )
2726 . await ?;
2827
2928 println ! ( "account: {account_id}" ) ;
Original file line number Diff line number Diff line change @@ -183,7 +183,6 @@ where
183183 /// client
184184 /// .basic_feed_item(account_id, title, image_url)
185185 /// .body("i figured out how to send messages to monzo from my computer...")
186- /// .send()
187186 /// .await?;
188187 /// #
189188 /// # Ok(())
@@ -242,7 +241,6 @@ where
242241 /// .transactions(account_id)
243242 /// .since(Utc::now() - Duration::days(10))
244243 /// .limit(10)
245- /// .send()
246244 /// .await?;
247245 /// #
248246 /// # Ok(())
@@ -269,7 +267,7 @@ where
269267 /// #
270268 /// let transaction_id = "TRANSACTION_ID";
271269 ///
272- /// let transactions = client.transaction(transaction_id).send(). await?;
270+ /// let transactions = client.transaction(transaction_id).await?;
273271 /// #
274272 /// # Ok(())
275273 /// # }
Original file line number Diff line number Diff line change 33pub use basic:: Request as Basic ;
44
55pub ( crate ) mod basic {
6+ use std:: future:: { Future , IntoFuture } ;
7+
68 use serde:: Serialize ;
79
810 use crate :: { client, endpoints:: Endpoint , Result } ;
@@ -99,11 +101,6 @@ pub(crate) mod basic {
99101 self . payload . params . body = Some ( body) ;
100102 self
101103 }
102-
103- /// Consume and send the [`Request`].
104- pub async fn send ( self ) -> Result < ( ) > {
105- self . client . handle_request ( & self ) . await
106- }
107104 }
108105
109106 impl < C > Endpoint for Request < ' _ , C >
@@ -121,6 +118,20 @@ pub(crate) mod basic {
121118 }
122119 }
123120
121+ impl < ' a , C > IntoFuture for Request < ' a , C >
122+ where
123+ C : client:: Inner ,
124+ {
125+ type Output = Result < ( ) > ;
126+
127+ type IntoFuture = impl Future < Output = Self :: Output > ;
128+
129+ /// Consume and send the [`Request`].
130+ fn into_future ( self ) -> Self :: IntoFuture {
131+ async move { self . client . handle_request ( & self ) . await }
132+ }
133+ }
134+
124135 #[ derive( Debug , Serialize ) ]
125136 struct Params < ' a > {
126137 #[ serde( rename = "params[title]" ) ]
Original file line number Diff line number Diff line change 1+ use std:: future:: { Future , IntoFuture } ;
2+
13use super :: Transaction ;
24use crate :: { client, endpoints:: Endpoint , Result } ;
35
5355 self . expand_merchant = true ;
5456 self
5557 }
58+ }
59+
60+ impl < ' a , C > IntoFuture for Request < ' a , C >
61+ where
62+ C : client:: Inner ,
63+ {
64+ type Output = Result < Transaction > ;
65+
66+ type IntoFuture = impl Future < Output = Self :: Output > ;
5667
5768 /// Consume the request and return the [`Transaction`]
58- pub async fn send ( self ) -> Result < Transaction > {
59- self . client . handle_request ( & self ) . await
69+ fn into_future ( self ) -> Self :: IntoFuture {
70+ async move { self . client . handle_request ( & self ) . await }
6071 }
6172}
Original file line number Diff line number Diff line change 1+ use std:: future:: { Future , IntoFuture } ;
2+
13use chrono:: { DateTime , Utc } ;
24use serde:: { Deserialize , Serialize } ;
35
@@ -78,17 +80,26 @@ where
7880 self . query . expand_merchant = Some ( "merchant" ) ;
7981 self
8082 }
83+ }
84+
85+ impl < ' a , C > IntoFuture for Request < ' a , C >
86+ where
87+ C : client:: Inner ,
88+ {
89+ type Output = Result < Vec < Transaction > > ;
90+
91+ type IntoFuture = impl Future < Output = Self :: Output > ;
8192
8293 /// Consume the request and return the list of [`Transaction`]s
83- pub async fn send ( self ) -> Result < Vec < Transaction > > {
94+ fn into_future ( self ) -> Self :: IntoFuture {
8495 #[ derive( Deserialize ) ]
8596 struct Response {
8697 transactions : Vec < Transaction > ,
8798 }
88-
89- let response: Response = self . client . handle_request ( & self ) . await ?;
90-
91- Ok ( response . transactions )
99+ async move {
100+ let response: Response = self . client . handle_request ( & self ) . await ?;
101+ Ok ( response . transactions )
102+ }
92103 }
93104}
94105
Original file line number Diff line number Diff line change 77) ]
88#![ warn( clippy:: pedantic) ]
99#![ allow( clippy:: missing_errors_doc) ]
10+ #![ feature( impl_trait_in_assoc_type) ]
1011
1112//! A Monzo client in pure rust.
1213//!
You can’t perform that action at this time.
0 commit comments