Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #[derive(Clone)]
- pub struct CompatClosure<C3, A, F3>(C3, PhantomData<A>, PhantomData<F3>) where
- F3: FutureExt,
- C3: FnOnce<A, Output = F3>;
- impl<C3, A, F3> Fn<A> for CompatClosure<C3, A, F3> where
- F3: TryFuture + FutureExt + Send + 'static,
- Pin<Box<dyn Future<Output = <F3 as Future>::Output> + Send>>: TryFutureExt,
- C3: Fn<A, Output = F3> {
- extern "rust-call" fn call(&self, args: A) -> Self::Output {
- self.0.call(args).boxed().compat()
- }
- }
- impl<C3, A, F3> FnMut<A> for CompatClosure<C3, A, F3> where
- F3: TryFuture + FutureExt + Send + 'static,
- Pin<Box<dyn Future<Output = <F3 as Future>::Output> + Send>>: TryFutureExt,
- C3: FnMut<A, Output = F3> {
- extern "rust-call" fn call_mut(&mut self, args: A) -> Self::Output {
- self.0.call_mut(args).boxed().compat()
- }
- }
- impl<C3, A, F3> FnOnce<A> for CompatClosure<C3, A, F3> where
- F3: TryFuture + FutureExt + Send + 'static,
- Pin<Box<dyn Future<Output = <F3 as Future>::Output> + Send>>: TryFutureExt,
- C3: FnOnce<A, Output = F3> {
- type Output = compat::Compat<Pin<Box<dyn Future<Output = <F3 as Future>::Output> + Send>>>;
- extern "rust-call" fn call_once(self, args: A) -> Self::Output {
- self.0.call_once(args).boxed().compat()
- }
- }
- pub trait ClosureCompat<A, F3> where
- Self: Sized + FnOnce<A, Output = F3>,
- F3: TryFuture + FutureExt + Send + 'static {
- fn asdf(self) -> CompatClosure<Self, A, F3>;
- }
- impl<C3, A, F3> ClosureCompat<A, F3> for C3 where
- F3: TryFuture + FutureExt + Send + 'static,
- C3: FnOnce<A, Output = F3> + Sized {
- fn asdf(self) -> CompatClosure<Self, A, F3> {
- CompatClosure(self, PhantomData, PhantomData)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement