Skip to content

Commit ab2823a

Browse files
committed
use 'IntoFutre' trait
1 parent 018d8ef commit ab2823a

File tree

6 files changed

+42
-7
lines changed

6 files changed

+42
-7
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::days(args.days))
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
@@ -149,7 +149,6 @@ where
149149
/// client
150150
/// .basic_feed_item(account_id, title, image_url)
151151
/// .body("i figured out how to send messages to monzo from my computer...")
152-
/// .send()
153152
/// .await?;
154153
/// #
155154
/// # Ok(())
@@ -212,7 +211,6 @@ where
212211
/// .transactions(account_id)
213212
/// .since(Utc::now() - Duration::days(10))
214213
/// .limit(10)
215-
/// .send()
216214
/// .await?;
217215
/// #
218216
/// # Ok(())
@@ -239,7 +237,7 @@ where
239237
/// #
240238
/// let transaction_id = "TRANSACTION_ID";
241239
///
242-
/// let transactions = client.transaction(transaction_id).send().await?;
240+
/// let transactions = client.transaction(transaction_id).await?;
243241
/// #
244242
/// # Ok(())
245243
/// # }

src/endpoints/feed_items.rs

Lines changed: 13 additions & 1 deletion
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, client::handle_request, endpoints::Endpoint, Result};
@@ -95,7 +97,7 @@ pub(crate) mod basic {
9597
}
9698

9799
/// Consume and send the [`Request`].
98-
pub async fn send(self) -> Result<()> {
100+
async fn send(self) -> Result<()> {
99101
handle_request(self.client, &self).await
100102
}
101103
}
@@ -114,6 +116,16 @@ pub(crate) mod basic {
114116
}
115117
}
116118

119+
impl<'a> IntoFuture for Request<'a> {
120+
type Output = Result<()>;
121+
122+
type IntoFuture = impl Future<Output = Self::Output>;
123+
124+
fn into_future(self) -> Self::IntoFuture {
125+
self.send()
126+
}
127+
}
128+
117129
#[derive(Debug, Serialize)]
118130
struct Params<'a> {
119131
#[serde(rename = "params[title]")]

src/endpoints/transactions/get.rs

Lines changed: 13 additions & 1 deletion
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::{
35
client::{self, handle_request},
@@ -52,7 +54,17 @@ impl<'a> Request<'a> {
5254
}
5355

5456
/// Consume the request and return the [`Transaction`]
55-
pub async fn send(self) -> Result<Transaction> {
57+
async fn send(self) -> Result<Transaction> {
5658
handle_request(self.client, &self).await
5759
}
5860
}
61+
62+
impl<'a> IntoFuture for Request<'a> {
63+
type Output = Result<Transaction>;
64+
65+
type IntoFuture = impl Future<Output = Self::Output>;
66+
67+
fn into_future(self) -> Self::IntoFuture {
68+
self.send()
69+
}
70+
}

src/endpoints/transactions/list.rs

Lines changed: 13 additions & 1 deletion
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

@@ -77,7 +79,7 @@ impl<'a> Request<'a> {
7779
}
7880

7981
/// Consume the request and return the list of [`Transaction`]s
80-
pub async fn send(self) -> Result<Vec<Transaction>> {
82+
async fn send(self) -> Result<Vec<Transaction>> {
8183
#[derive(Deserialize)]
8284
struct Response {
8385
transactions: Vec<Transaction>,
@@ -89,6 +91,16 @@ impl<'a> Request<'a> {
8991
}
9092
}
9193

94+
impl<'a> IntoFuture for Request<'a> {
95+
type Output = Result<Vec<Transaction>>;
96+
97+
type IntoFuture = impl Future<Output = Self::Output>;
98+
99+
fn into_future(self) -> Self::IntoFuture {
100+
self.send()
101+
}
102+
}
103+
92104
#[derive(Serialize, Debug)]
93105
struct Query<'a> {
94106
account_id: &'a str,

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
)]
88
#![warn(clippy::pedantic)]
99
#![allow(clippy::missing_errors_doc)]
10+
#![feature(into_future)]
11+
#![feature(type_alias_impl_trait)]
1012

1113
//! A Monzo client in pure rust.
1214
//!

0 commit comments

Comments
 (0)