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

How to wrap hyper::client with generic connector? #2071

Closed
ggriffiniii opened this issue Dec 11, 2019 · 1 comment
Closed

How to wrap hyper::client with generic connector? #2071

ggriffiniii opened this issue Dec 11, 2019 · 1 comment

Comments

@ggriffiniii
Copy link

I'm trying to port some code to the new hyper to take advantage of async/await, but I'm running into a problem of not being able to wrap a generic hyper::Client. The code I'm working on is yup-oauth2 which accepts an arbitrary hyper::Client from the user and would like to be generic over any connector the user provides.

A distilled form of the problem can be seen here:

async fn make_request<C>(client: &hyper::Client<C>)
where
    C: <what can I put here>,
{
    println!("{:?}", client.get("http://www.google.com").await.unwrap())
}

We used to bound it by the hyper::client::connect::Connect, but that trait is now sealed making it impossible to reference. I understand that users shouldn't need to implement Connect any longer because of the blanket impl for Service, but by putting it within hidden module it can no longer be referenced by external crates for trait bounds like above. Am I missing a way to write a function like make_request?

It seems like Connect should be publicly visible, but keep the Sealed trait hidden. That would prevent people from being able to implement it, but still allow the trait to be referenced by users.

@dekellum
Copy link

It's currently not pretty, and possibly still evolving, but see #2051 (comment) and subsequent comments.

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