-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(build): Add #[deprecated]
to deprecated client methods
#1879
Conversation
tonic-build/src/lib.rs
Outdated
@@ -144,6 +144,8 @@ pub trait Method { | |||
fn server_streaming(&self) -> bool; | |||
/// Get comments about this item. | |||
fn comment(&self) -> &[Self::Comment]; | |||
/// Method is deprecated. | |||
fn deprecated(&self) -> bool; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good idea, I've added it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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::deprecated
which returns if the method is deprecated and is checked when the client code is generated.I'd consider this a breaking change, as theMethod
trait is publicly exposed and the code will now emit warnings if a deprecated generated method is called.Method::deprecated
has a default implementation which always returnsfalse
.