finish_fn with .await (IntoFuture implementation for the builder) #293
Replies: 2 comments 1 reply
-
|
Hi! It's definitely possible, but this requires boxing the future. That's why use std::future::{Future, IntoFuture};
use std::pin::Pin;
#[bon::builder]
async fn fetch(wallet: String, chain: String) -> String {
format!("{wallet}:{chain}")
}
impl<S: fetch_builder::IsComplete + 'static> IntoFuture for FetchBuilder<S> {
type Output = String;
type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
fn into_future(self) -> Self::IntoFuture {
Box::pin(self.call())
}
}
#[tokio::main]
async fn main() {
// This works
let ret = fetch()
.wallet("wallet".to_owned())
.chain("chain".to_owned())
.call()
.await;
// and this works too
let ret = fetch()
.wallet("wallet".to_owned())
.chain("chain".to_owned())
.await;
}If you want to enforce not using the |
Beta Was this translation helpful? Give feedback.
-
|
@Veetaha You can use 'impl Future' nightly, is it possible to add this feature to experimental bon's features? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
is it possible to implement IntoFuture for asynchronous function and make
.awaitlike.call()?Beta Was this translation helpful? Give feedback.
All reactions