Skip to content

Allow creation of async variant for non-async triats #40

@adityashah1212

Description

@adityashah1212

Not sure if this was considered when designing the crate, but I was hoping to have the following use case as handled by this crate as well

#[trait_variant::make(async_variant = [LocalAsyncSomeTrait, AsyncSomeTrait: Send])]
trait SomeTrait {
    #[variant(make_async)]
    fn blocking_method(&self) -> Result<Value, Error>;

    #[variant(inherit)]
    fn method_to_auto_impl(&self);

    #[variant(skip)]
    fn method_is_skipped(&self);
}

The above would expand to

trait LocalAsyncSomeTrait: SomeTrait {
    fn blocking_method(&self) -> impl Future<Output = Result<Value, Error>>;

    fn method_to_auto_impl(&self) {
         <Self as SomeTrait>::method_to_auto_impl(self)
    }
}

trait AsyncSomeTrait: LocalAsyncSomeTrait {
    fn blocking_method(&self) -> impl Future<Output = Result<Value, Error>> + Send;

    fn method_to_auto_impl(&self) {
         <Self as SomeTrait>::method_to_auto_impl(self)
    }
}

This way a single crate can defined multiple traits. This is in no way refined and probably needs some design, but would be great addition in my opinion

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions