diff --git a/ambassador/src/register.rs b/ambassador/src/register.rs index 37694ac..39669fe 100644 --- a/ambassador/src/register.rs +++ b/ambassador/src/register.rs @@ -321,7 +321,12 @@ fn build_method_invocation( let generics = method_sig.generics.split_for_impl().1; let turbofish = generics.as_turbofish(); + let post = if original_method.sig.asyncness.is_some() { + quote!(.await) + } else { + quote!() + }; - let method_invocation = quote! { #field_ident.#method_ident #turbofish(#argument_list) }; + let method_invocation = quote! { #field_ident.#method_ident #turbofish(#argument_list) #post }; method_invocation } diff --git a/ambassador/tests/compiletest.rs b/ambassador/tests/compiletest.rs index 1c522d9..a137f37 100644 --- a/ambassador/tests/compiletest.rs +++ b/ambassador/tests/compiletest.rs @@ -6,7 +6,7 @@ fn run_mode(mode: &'static str) { let mut config = compiletest::Config::default(); config.mode = mode.parse().expect("Invalid mode"); - config.target_rustcflags = Some("-L ../target/debug/deps".to_owned()); + config.target_rustcflags = Some("-L ../target/debug/deps --edition 2018".to_owned()); config.src_base = PathBuf::from(format!("tests/{}", mode)); config.link_deps(); // Populate config.target_rustcflags with dependencies on the path diff --git a/ambassador/tests/run-pass/async.rs b/ambassador/tests/run-pass/async.rs new file mode 100644 index 0000000..da373c8 --- /dev/null +++ b/ambassador/tests/run-pass/async.rs @@ -0,0 +1,51 @@ +extern crate ambassador; + +use ambassador::*; + +pub struct Base1 {} + +#[derive(Delegate)] +#[delegate(Hello, target = "self")] +pub struct Base2 {} + +impl Base2 { + async fn hello(&self) {} +} + +#[delegatable_trait] +trait Hello { + async fn hello(&self); +} + +impl Hello for Base1 { + async fn hello(&self) {} +} + +#[derive(Delegate)] +#[delegate(Hello)] +pub struct Dram { + inner: Base1, +} + +#[derive(Delegate)] +#[delegate(Hello)] +pub enum Either { + Base1(Base1), + Base2(Base2), +} + +struct OpBase(Option); + +#[delegate_to_methods] +#[delegate(Hello, target_ref = "unwrap_ref")] +impl OpBase { + fn unwrap_ref(&self) -> &Base1 { + self.0.as_ref().unwrap() + } +} + +fn main() { + let d = Dram { inner: Base1 {} }; + + let _ = d.hello(); +}