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

Server/Router type signatures are not grok-able #874

Closed
iitalics opened this issue Dec 28, 2021 · 2 comments
Closed

Server/Router type signatures are not grok-able #874

iitalics opened this issue Dec 28, 2021 · 2 comments

Comments

@iitalics
Copy link

Bug Report

Version

0.6.2

Platform

any

Crates

tonic

Description

The type signatures in the Server/Router builders are convoluted and reference private types, which makes them completely un-understandable to users.

For example, from tonic::transport::server::Router:

pub async fn serve<ResBody>(self, addr: SocketAddr) -> Result<(), Error> where
    L: Layer<Routes<A, B, Request<Body>>>,
    L::Service: Service<Request<Body>, Response = Response<ResBody>> + Clone + Send + 'static,
    <<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Future: Send + 'static,
    <<L as Layer<Routes<A, B, Request<Body>>>>::Service as Service<Request<Body>>>::Error: Into<Box<dyn Error + Send + Sync>> + Send,
    ResBody: Body<Data = Bytes> + Send + 'static,
    ResBody::Error: Into<Box<dyn Error + Send + Sync>>, 

Besides this just being an incredibly complex type signature, users can't derive any information out of it because the type Routes is private. In particular, you can't figure out what the associated types mean (or what the constraints imply) without going to the source code.

@davidpdrsn
Copy link
Member

What specific questions do you have?

The trait bounds are not intentionally complicated but exist to enable other features. You're welcome to make suggestions on how to simplify them.

The Routes type is private because users shouldn't have to use it. That'll be changed in #830 which makes the routing simpler, including simplifying some types.

@LucioFranco
Copy link
Member

The compiler errors produced from these bounds are what is important. Most of these bounds just add send requirements and in reality can be mostly ignored. Once rust gets proper trait aliases we can consider using those to reduce it. Going to close this but feel free to reopen it if you have any more questions!

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

3 participants