google / tarpc

An RPC framework for Rust with a focus on ease of use.
MIT License
3.09k stars 189 forks source link

Generic type parameters #412

Closed jimouris closed 7 months ago

jimouris commented 7 months ago

Can I have a generic type as a parameter to the service?

#[tarpc::service]
trait Service<T> {

async fn hello(name: T) -> String;
}

or maybe as

#[tarpc::service]
trait Service {

async fn hello<T>(name: T) -> String;
}

?

Thanks

tikue commented 7 months ago

Unfortunately no :( I haven't made any progress on this since filing https://github.com/google/tarpc/issues/257.

jimouris commented 7 months ago

Oh, no problem, thank you for your quick response! I also see that defining custom types inside the trait is not allowed. Is there any way around that or is it just a blocker for now?

jimouris commented 7 months ago

Also, please feel free to close this issue since it's a duplicate of #257.

tikue commented 7 months ago

Oh, no problem, thank you for your quick response! I also see that defining custom types inside the trait is not allowed. Is there any way around that or is it just a blocker for now?

I think it's essentially a blocker. RPC services can't be generic over types at all, whether that's a type parameter on the trait or an associated type in the trait.

Closing in favor of #257 but feel free to comment more there!