ut

Attribute Macro clone_impl

Source
#[clone_impl]
Expand description

Clones an group of async functions in an impl to a new sub structure

This is useful when you want to support both async and sync functions in a struct implementation.

ยงExamples

#[derive(Default)]
pub struct Example {
  pub fooers: Fooers,
}

#[derive(Default)]
pub struct ExampleBlocking {
  pub fooers: FooersBlocking,
}

#[derive(Default)]
pub struct Fooers;

#[derive(Default)]
pub struct FooersBlocking;

#[ut::clone_impl]
impl Fooers {
  pub async fn foo(&self, input: &str) -> String {
    format!("I am {} now", input)
  }
}

let out = ExampleBlocking::default().fooers.foo("sync");
assert_eq!(out, "I am sync now".to_owned())