-
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): support adding attributes to clients and servers #684
Conversation
} else if pattern == path { | ||
true | ||
} else { | ||
let pattern_segments = pattern.split('.').collect::<Vec<_>>(); |
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.
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.
LGTM, left a few questions.
8bb9130
to
68fae34
Compare
00c6df6
to
37ccbbd
Compare
755b989
to
55a7554
Compare
tonic-build/src/lib.rs
Outdated
/// `mod` attributes. | ||
pub module: Vec<(String, String)>, | ||
/// `struct` attributes. | ||
pub structure: Vec<(String, String)>, |
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.
why do these need to be public?
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.
Great! Thank you for getting this over the finish line!
Motivation
Implements #504.
Having the ability to add attributes to generated servers and clients allows things like feature gating or deriving additional service functionality without the need for a fork.
Solution
This PR only changes
tonic-build
. Four new methods are added toBuilder
:server_mod_attribute
mod
wrapping the server implementation.server_attribute
struct
.client_mod_attribute
mod
wrapping the client implementation.client_attribute
struct
.These are all optional values. Calling them more than once is additive.
Each method accepts a
pattern
and anattribute
.pattern
follows similar rules astonic
's attribute matching rules.If
pattern
matches for a given service, the respectiveattribute
values are parsed assyn::Attribute
s and added to the generated code inserver::generate
andclient::generate
.