Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::future::Future;
- pub trait X: Clone + Send + Unpin + Sync {
- fn x(&self) -> Box<dyn Future<Output = ()> + Unpin + Send>;
- }
- pub fn c<'a, X1: X + 'a>(x: &X1) -> Box<dyn Future<Output = ()> + Unpin + Send + 'a> {
- let x = x.clone();
- let res = x.x().then(move |_| x.x());
- Box::new(res)
- }
- impl X for &() {
- fn x(&self) -> Box<dyn Future<Output = ()> + Unpin + Send> {
- Box::new(Box::pin(async {}))
- }
- }
- fn main() {
- let _ = {
- let val = ();
- let reference = &val;
- c(&reference)
- };
- }
- /// ----
- use std::pin::Pin;
- trait FutureExt: Future {
- fn then<'a, F: Future + Send>(self, f: impl FnOnce(Self::Output) -> F + Send + 'a) -> Pin<Box<dyn Future<Output = F::Output> + Send + 'a>> where Self: Send + Sized + 'a, Self::Output: Send {
- Box::pin(async { f(self.await).await })
- }
- }
- impl<T: Future + ?Sized> FutureExt for T {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement