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

Export GrpcWeb #1121

Closed
wants to merge 1 commit into from
Closed

Export GrpcWeb #1121

wants to merge 1 commit into from

Conversation

aarashy
Copy link

@aarashy aarashy commented Oct 21, 2022

Motivation

I was trying to write a subroutine like the following:

pub fn grpc_web_enable<S>(service: S) -> GrpcWeb<S>
where
    S: Service<http::Request<hyper::Body>, Response = http::Response<BoxBody>>,
    S: NamedService + Clone + Send + 'static,
    S::Future: Send + 'static,
    S::Error: Into<Box<dyn std::error::Error + Send + Sync>> + Send,
{
    let web_config =
        tonic_web::Config::default().expose_headers(["grpc-status-details-bin"].into_iter());
    web_config.enable(service)
}

But because GrpcWeb isn't exported, this is impossible. It's also not good enough to return an impl Trait Object, because, when you try to call add_service on the output, you will run into rust-lang/rust#52662 (there is a required trait bound on the associated Future of the Service which cannot be set)

Solution

GrpcWeb is already a pub struct, it was just part of a hidden mod.

The Config::enable function is a pub function which returns a private struct. I generally think any struct returned by a pub function should be a pub struct - even if all of its fields and methods are private.

@LucioFranco
Copy link
Member

#1123 will include this change, going to close this thanks for the help!

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

Successfully merging this pull request may close these issues.

2 participants