Closed ShaneMurphy2 closed 6 months ago
Thanks for the suggestion! I agree this could be supported.
It'd be nice to replace the derive_serde
arg with something generic enough to support this new use case. Maybe something like this would be possible:
#[tarpc::service(derive = [tarpc::serde::Serialize, tarpc::serde::Deserialize, Clone, Hash])]
service World {
async fn hello(message: String) -> String;
}
@tikue Got a first cut up on a branch: https://github.com/ShaneMurphy2/tarpc/tree/customizable-derives, let me know what you think so far.
Still need to see what breaks by changing the macro syntax, but the core use case works.
Looks nice! It'd be nice for derive_serde
and derive
to be mutually exclusive, so that people are encouraged to make the switch. In particular:
derive_serde
and derive
at the same time should be an errorderive
should only derive Serialize/Deserialize when they are explicitly listedderive_serde
is deprecated - output a warning when it is used, and suggest instead using either derive = []
to disable, or derive = [Serialize, Deserialize]
to explicitly enablederive
can derive Serialize/Deserialize by default.Looks nice! It'd be nice for
derive_serde
andderive
to be mutually exclusive, so that people are encouraged to make the switch. In particular:
derive_serde
andderive
at the same time should be an errorderive
should only derive Serialize/Deserialize when they are explicitly listedderive_serde
is deprecated - output a warning when it is used, and suggest instead using eitherderive = []
to disable, orderive = [Serialize, Deserialize]
to explicitly enable- for backwards compatibility, absence of
derive
can derive Serialize/Deserialize by default.
On it 👍
@tikue PR is up!
Currently
tarpc::service
creates request and response types that are not clone. This makes it difficult it difficult to test and mock. It would be nice if the service macro used an attribute macro to control adding derives for things likePartialEq
,Clone
, orHash
. Is there any reason not to do this? If there isn't, I can take a stab at it.