http-rs / surf

Fast and friendly HTTP client framework for async Rust
https://docs.rs/surf
Apache License 2.0
1.47k stars 120 forks source link

make NativeClient public #96

Closed frostRed closed 4 years ago

frostRed commented 5 years ago

I have a problem when I want to wrap my client.

The Problem like this: https://stackoverflow.com/questions/45253784/expected-type-parameter-found-struct.

And my code:

use surf::{middleware::HttpClient, Client};

pub struct NodeRpcClient2<C: HttpClient> {
    client: Client<C>,
    upstream_url: String,
}

impl<C: HttpClient> NodeRpcClient2<C> {
    pub fn new(url: String) -> Self {
        let client = Client::new();
        NodeRpcClient2 {
            client,
            upstream_url: url,
        }
    }
}

69 seems to work.

yoshuawuyts commented 5 years ago

@frostRed good point; yeah we should go through with that change. All we need now is a patch for it, and then we can use that to cut a 2.0 release. I think it's time.

strohel commented 4 years ago

I think this was resolved in #124 by moving NativeClient into separate crate http-client (where it is public).

andrewbanchich commented 4 years ago

I can't figure out how to import NativeClient with this. The surf's 2.0.0-alpha.4 docs now have NativeClient as a link in function signatures since it's public, but when I click it it just takes me to a resource does not exist page. I also can't find a way to import it from the http_client crate. When I try, I just get

could not find `native_client` in `http_client`
andrewbanchich commented 4 years ago

Maybe surf could re-export NativeClient so that we don't need to add another dependency directly just for this use case?

goto-bus-stop commented 4 years ago

Since #193 you don't need the NativeClient at all anymore because surf::Client does not have a generic parameter :)