struct Qqq {} impl Qqq { fn foo(&self) { dbg!("foo"); } async fn bar(&self, x: i32) { dbg!("bar", x); } async fn baz(&self, y: String, z: Vec) { dbg!("baz", y, z); } } // Begin of the part which is supposed to be auto-generated enum QqqEnum { Foo, Bar { x: i32 }, Baz { y: String, z: Vec }, } impl QqqEnum { async fn call(self, o: &Qqq) { match self { QqqEnum::Foo => o.foo(), QqqEnum::Bar { x } => o.bar(x).await, QqqEnum::Baz { y, z } => o.baz(y, z).await, } } #[allow(unused)] async fn call_mut(self, o: &mut Qqq) { match self { QqqEnum::Foo => o.foo(), QqqEnum::Bar { x } => o.bar(x).await, QqqEnum::Baz { y, z } => o.baz(y, z).await, } } #[allow(unused)] async fn call_once(self, o: Qqq) { match self { QqqEnum::Foo => o.foo(), QqqEnum::Bar { x } => o.bar(x).await, QqqEnum::Baz { y, z } => o.baz(y, z).await, } } } struct QqqUsualProxy Result<(), E>>(F); impl Result<(), E>> QqqUsualProxy { fn try_foo(&self) -> Result<(), E> { self.0(QqqEnum::Foo) } fn try_bar(&self, x: i32) -> Result<(), E> { self.0(QqqEnum::Bar { x }) } fn try_baz(&self, y: String, z: Vec) -> Result<(), E> { self.0(QqqEnum::Baz { y, z }) } } struct QqqAsyncProxy Fu, Fu: std::future::Future>>(F); impl Fu, Fu: std::future::Future>> QqqAsyncProxy { async fn try_foo(&self) -> Result<(), E> { self.0(QqqEnum::Foo).await } async fn try_bar(&self, x: i32) -> Result<(), E> { self.0(QqqEnum::Bar { x }).await } async fn try_baz(&self, y: String, z: Vec) -> Result<(), E> { self.0(QqqEnum::Baz { y, z }).await } } // End of the part which is supposed to be auto-generated #[test] fn async_to_async() { let o = Qqq {}; let p = QqqAsyncProxy::(|c: QqqEnum| async { Ok(c.call(&o).await) }); futures::executor::block_on(p.try_foo()).unwrap(); futures::executor::block_on(p.try_bar(4)).unwrap(); futures::executor::block_on(p.try_baz("qqq".to_owned(), vec![])).unwrap(); } #[test] fn usual_to_async() { let o = Qqq {}; let p = QqqUsualProxy::(|c: QqqEnum| Ok(futures::executor::block_on(c.call(&o)))); p.try_foo().unwrap(); p.try_bar(4).unwrap(); p.try_baz("qqq".to_owned(), vec![]).unwrap(); }