Skip to content

Commit 8e38f96

Browse files
danieleadesdaniel.eades
authored and
daniel.eades
committed
use 'IntoFuture' trait
1 parent 2c52ad6 commit 8e38f96

File tree

6 files changed

+47
-16
lines changed

6 files changed

+47
-16
lines changed

examples/list_transactions.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff 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}");

src/client.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ where
184184
/// client
185185
/// .basic_feed_item(account_id, title, image_url)
186186
/// .body("i figured out how to send messages to monzo from my computer...")
187-
/// .send()
188187
/// .await?;
189188
/// #
190189
/// # Ok(())
@@ -243,7 +242,6 @@ where
243242
/// .transactions(account_id)
244243
/// .since(Utc::now() - Duration::days(10))
245244
/// .limit(10)
246-
/// .send()
247245
/// .await?;
248246
/// #
249247
/// # Ok(())
@@ -270,7 +268,7 @@ where
270268
/// #
271269
/// let transaction_id = "TRANSACTION_ID";
272270
///
273-
/// let transactions = client.transaction(transaction_id).send().await?;
271+
/// let transactions = client.transaction(transaction_id).await?;
274272
/// #
275273
/// # Ok(())
276274
/// # }

src/endpoints/feed_items.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
pub use basic::Request as Basic;
44

55
pub(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]")]

src/endpoints/transactions/get.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::future::{Future, IntoFuture};
2+
13
use super::Transaction;
24
use crate::{client, endpoints::Endpoint, Result};
35

@@ -53,9 +55,18 @@ where
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
}

src/endpoints/transactions/list.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::future::{Future, IntoFuture};
2+
13
use chrono::{DateTime, Utc};
24
use 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

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
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
//!

0 commit comments

Comments
 (0)