-
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(tonic): expose Interceptor
trait
#713
Conversation
I'm thinking going straight to a tower Perhaps a function pointer like |
I did that, but found myself having to copy+paste this part of tonic, which is less than ideal. BTW, since regular functions (with the right sig) implement this trait anyways, I don't really see it as any more mental overhead than already exists. (Thanks for the quick response, BTW!) |
You're right that it's just one more trait but in my experience tower/services/middleware is already hard to grasp for some users. This trait does introduce another step you have to wrap your head around. I think if you use the types from the |
Correct me if I'm wrong, but I tried that and there's no way to access the |
The headers on the request is actually the same as the metadata. Tonic maps between the types internally. Same goes for the extensions. |
And you can use |
I got around my original issue by implementing the My opinion is that the small addition this PR adds to the complexity factor of understanding But I completely understand your reasoning and please feel free to close this pull request if I you're still not convinced ;) |
@LucioFranco what do you think? |
For what it's worth, this is the code that I could've avoided writing if this PR was accepted: https://github.com/etcdv3/etcd-client/pull/21/files#diff-212eed958dda431dc3bf15be7424ef556201e53143bbe8b19bb80e19e22e5cd9 It's not a disaster, but I generally will always prefer to delete existing code rather than adding new code :) And regardless - thanks for all your hard work! |
You might be able to use |
I'm not opposed to exposing a trait, we can always remove it if we find its wrong down the line and tonic is still a ways away from 1.0 |
@LucioFranco rebased to resolve conflicts and force pushed |
Alright cool. Then lets move forward with this 😊 Given that we recently shipped a breaking release (0.5) I doubt we're going to make another breaking release anytime soon. So it would be cool to find a way to add this without breaking changes. @yotamofek what do you think? |
If I rename *unless there's some very contrived scenario which I can't think of that will cause breakage? |
Another small thought: The whole reason I opened this PR was to allow myself (as a downstream user of I can say that as a consumer, I would probably not mind jumping two minor versions at a time if it meant an easier upgrade path. But this is really just my $0.02, and I'll be happy to try to make this PR be consistent with the 0.5 API surface. |
I think we should at least explore what a non-breaking version of what this might look like before we decide to ship another breaking release. I don't think shipping two breaking release within less than two weeks is ideal, unless something is broken which I don't think is the case here 🤷 |
Interceptor
trait.Interceptor
trait
@davidpdrsn |
I'm going on vacation for a few weeks. Will check this out when I'm done. @LucioFranco feel free to take over if you have the time. |
Enjoy your time off, thanks for all the effort so far! |
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.
I think this should work, I can't find a situation where this would be a breaking change now that you've added the deprecated.
Motivation
Found myself wanting to be able to explicitly type a wrapped client (or server, for that matter), i.e.:
This is currently impossible (until
impl
ing theFn
traits becomes stable, which will take a while).Solution
Expose an
Interceptor
trait that is implemented for the function signatures of interceptors, but can also be implemented by downstream crates on custom types.I think a semver change can be avoided by not renaming
interceptor_fn
->interceptor_layer
, but IMHO the name change is worthwhile.