diff --git a/examples/list_transactions.rs b/examples/list_transactions.rs index 916e969..12e61b7 100644 --- a/examples/list_transactions.rs +++ b/examples/list_transactions.rs @@ -23,7 +23,6 @@ async fn main() -> monzo::Result<()> { .transactions(account_id) .since(Utc::now() - Duration::try_days(args.days).unwrap()) .limit(args.limit) - .send() .await?; println!("account: {account_id}"); diff --git a/src/client.rs b/src/client.rs index 6c0bb75..576b65b 100644 --- a/src/client.rs +++ b/src/client.rs @@ -184,7 +184,6 @@ where /// client /// .basic_feed_item(account_id, title, image_url) /// .body("i figured out how to send messages to monzo from my computer...") - /// .send() /// .await?; /// # /// # Ok(()) @@ -243,7 +242,6 @@ where /// .transactions(account_id) /// .since(Utc::now() - Duration::days(10)) /// .limit(10) - /// .send() /// .await?; /// # /// # Ok(()) @@ -270,7 +268,7 @@ where /// # /// let transaction_id = "TRANSACTION_ID"; /// - /// let transactions = client.transaction(transaction_id).send().await?; + /// let transactions = client.transaction(transaction_id).await?; /// # /// # Ok(()) /// # } diff --git a/src/endpoints/feed_items.rs b/src/endpoints/feed_items.rs index a7bdcdd..932b96f 100644 --- a/src/endpoints/feed_items.rs +++ b/src/endpoints/feed_items.rs @@ -3,6 +3,8 @@ pub use basic::Request as Basic; pub(crate) mod basic { + use std::future::{Future, IntoFuture}; + use serde::Serialize; use crate::{client, endpoints::Endpoint, Result}; @@ -99,11 +101,6 @@ pub(crate) mod basic { self.payload.params.body = Some(body); self } - - /// Consume and send the [`Request`]. - pub async fn send(self) -> Result<()> { - self.client.handle_request(&self).await - } } impl<'a, C> Endpoint for Request<'a, C> @@ -121,6 +118,20 @@ pub(crate) mod basic { } } + impl<'a, C> IntoFuture for Request<'a, C> + where + C: client::Inner, + { + type Output = Result<()>; + + type IntoFuture = impl Future; + + /// Consume and send the [`Request`]. + fn into_future(self) -> Self::IntoFuture { + async move { self.client.handle_request(&self).await } + } + } + #[derive(Debug, Serialize)] struct Params<'a> { #[serde(rename = "params[title]")] diff --git a/src/endpoints/transactions/get.rs b/src/endpoints/transactions/get.rs index d7e5b0b..0248c38 100644 --- a/src/endpoints/transactions/get.rs +++ b/src/endpoints/transactions/get.rs @@ -1,3 +1,5 @@ +use std::future::{Future, IntoFuture}; + use super::Transaction; use crate::{client, endpoints::Endpoint, Result}; @@ -53,9 +55,18 @@ where self.expand_merchant = true; self } +} + +impl<'a, C> IntoFuture for Request<'a, C> +where + C: client::Inner, +{ + type Output = Result; + + type IntoFuture = impl Future; /// Consume the request and return the [`Transaction`] - pub async fn send(self) -> Result { - self.client.handle_request(&self).await + fn into_future(self) -> Self::IntoFuture { + async move { self.client.handle_request(&self).await } } } diff --git a/src/endpoints/transactions/list.rs b/src/endpoints/transactions/list.rs index 8b2e2df..99bd810 100644 --- a/src/endpoints/transactions/list.rs +++ b/src/endpoints/transactions/list.rs @@ -1,3 +1,5 @@ +use std::future::{Future, IntoFuture}; + use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; @@ -78,17 +80,26 @@ where self.query.expand_merchant = Some("merchant"); self } +} + +impl<'a, C> IntoFuture for Request<'a, C> +where + C: client::Inner, +{ + type Output = Result>; + + type IntoFuture = impl Future; /// Consume the request and return the list of [`Transaction`]s - pub async fn send(self) -> Result> { + fn into_future(self) -> Self::IntoFuture { #[derive(Deserialize)] struct Response { transactions: Vec, } - - let response: Response = self.client.handle_request(&self).await?; - - Ok(response.transactions) + async move { + let response: Response = self.client.handle_request(&self).await?; + Ok(response.transactions) + } } } diff --git a/src/lib.rs b/src/lib.rs index 47d8872..bd7aaa5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,6 +7,7 @@ )] #![warn(clippy::pedantic)] #![allow(clippy::missing_errors_doc)] +#![feature(impl_trait_in_assoc_type)] //! A Monzo client in pure rust. //!