feat(build): Add #[deprecated] to deprecated client methods#1879
feat(build): Add #[deprecated] to deprecated client methods#1879djc merged 3 commits intohyperium:masterfrom bytedream:feat/deprecated-client-method
#[deprecated] to deprecated client methods#1879Conversation
tonic-build/src/lib.rs
Outdated
| /// Get comments about this item. | ||
| fn comment(&self) -> &[Self::Comment]; | ||
| /// Method is deprecated. | ||
| fn deprecated(&self) -> bool; |
There was a problem hiding this comment.
Could we give this a default implementation that yields false? That would make this a non-breaking change, which might be nice, and it seems conceptually reasonable.
There was a problem hiding this comment.
For now I agree to make this setting false by default, and I think it would be good to set it to true in the future breaking release.
There was a problem hiding this comment.
That's a good idea, I've added it
There was a problem hiding this comment.
For now I agree to make this setting false by default, and I think it would be good to set it to true in the future breaking release.
Why? That doesn't make much sense to me.
There was a problem hiding this comment.
What I intended to mean was to not mark the code generated from the proto's deprecated as deprecated by default this time, and to enable it in the next major release. And I just noticed that I was commenting on something different than the perspective of your review.
There was a problem hiding this comment.
Ah, so you mean removing the default implementation when we release 0.13? That makes sense to me.
Motivation
When an rpc method is marked as deprecated, tonic currently doesn't forward it to the user (#1512).
Solution
This PR adds the
#[deprecated]attribute to generated rust client methods that are marked as deprecated in a protobuf file. I've addedMethod::deprecatedwhich returns if the method is deprecated and is checked when the client code is generated.I'd consider this a breaking change, as theMethodtrait is publicly exposed and the code will now emit warnings if a deprecated generated method is called.Method::deprecatedhas a default implementation which always returnsfalse.