Is it possible to express bounds on a late bounded asyn fn?

⚓ rust    📅 2025-07-03    👤 surdeus    👁️ 2      

surdeus

I want to change the

fn x<'a>(_: &'a i32) -> impl Future<Output = i32> + 'a

to

fn x<'a>(_: &'a i32) -> Pin<Box<impl Future<Output = i32> + 'a>>

Seems it can be achieved by macros, but I am trying to avoid macro, by trying some code like the following:

    fn boxed<F, R, T, U>(
        f: F,
    ) -> impl Fn(&mut T) -> Pin<Box<dyn Future<Output = U> + Send + '_>> + Send + Sync + Copy + 'static
    where
        F: for<'a> Fn(&'a mut T) -> R + Send + Sync + Copy + 'static,  // how to relate 'a to -
        T: Message + Default + 'static,                                //                     |
        U: Message + 'static,                                          //                     |
        R: Future<Output = U> + Send + 'a,  // <----------------------------------------------- 
    {
        move |req| Box::pin(f(req))
    }

But I found I am stucked at how to express bounds on the returned future, which is a late bounded parameter from the input argument.

It seems bo way out for me.

2 posts - 2 participants

Read full topic

🏷️ rust_feed