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 |
0 replies
|
@Veetaha You can use 'impl Future' nightly, is it possible to add this feature to experimental bon's features? |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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()?All reactions