Skip to content
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

Conditionaly adding services to router #265

Closed
hlb8122 opened this issue Feb 14, 2020 · 3 comments
Closed

Conditionaly adding services to router #265

hlb8122 opened this issue Feb 14, 2020 · 3 comments

Comments

@hlb8122
Copy link
Contributor

hlb8122 commented Feb 14, 2020

Feature Request

Motivation

I have a server which will enjoy up to 5 different services, each of which should be able to be enable/disabled at boot time. Currently there seems to be no way to do this without 2^5 different branches.

Proposal

Diesel has a similar problem when conditionally constructing queries, their solution is to provide a into_boxed() method.

A similar method could be added to Router.

A subsequent problem is that there is no way to generate a router with no services from a Server - this would also be required to conditionally add services. This could be done via a into_router() method on the Server.

The potential drawbacks here are that doing this may have unintended overhead due to the required boxing?

@LucioFranco
Copy link
Member

So I unfortunately think this is not possible right now due to our https://docs.rs/tonic/0.1.1/tonic/transport/trait.NamedService.html#associatedconstant.NAME trait since it contains a const type. This makes it hard to implement Either for services. We also can't do the same for a trait object since the type system relies upon knowing the type to generate the correct path check.

So to implement this we would need to make a breaking change. So I'm curious if maybe using a macro could help here? If you end up running into many branches you may wan to use another type of router than the one tonic provides.

@hlb8122
Copy link
Contributor Author

hlb8122 commented Feb 19, 2020

@LucioFranco I think a macro would be great substitute as long as n isn't too large, yes. I appreciate the modularity of tonic allowing me to switch out the router if I wish.

Wondering about another possibility:
Instead of conditionally adding a service X you conditionally switch X out for an "empty service" with the same signature which always returns unavailable (or whatever is appropriate). Does that sound feasible?

@LucioFranco
Copy link
Member

I am not sure that will work but I'd be open to a PR for that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants