Skip to content

Commit 7b6e3d9

Browse files
authored
Merge pull request #68 from Fishrock123/h1-client-debug-struct
feat: better debug struct for H1Client
2 parents 7726816 + 492f72c commit 7b6e3d9

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

examples/print_client_debug.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use http_client::HttpClient;
2+
use http_types::{Method, Request};
3+
4+
#[cfg(any(feature = "h1_client", feature = "docs"))]
5+
use http_client::h1::H1Client as Client;
6+
#[cfg(all(feature = "hyper_client", not(feature = "docs")))]
7+
use http_client::hyper::HyperClient as Client;
8+
#[cfg(all(feature = "curl_client", not(feature = "docs")))]
9+
use http_client::isahc::IsahcClient as Client;
10+
#[cfg(all(feature = "wasm_client", not(feature = "docs")))]
11+
use http_client::wasm::WasmClient as Client;
12+
13+
#[async_std::main]
14+
async fn main() {
15+
let client = Client::new();
16+
17+
let req = Request::new(Method::Get, "http://example.org");
18+
19+
client.send(req).await.unwrap();
20+
21+
dbg!(client);
22+
}

src/h1/mod.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,40 @@ pub struct H1Client {
3737

3838
impl Debug for H1Client {
3939
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40-
f.write_str("H1Client")
40+
f.debug_struct("H1Client")
41+
.field(
42+
"http_pools",
43+
&self
44+
.http_pools
45+
.iter()
46+
.map(|pool| {
47+
let status = pool.status();
48+
format!(
49+
"Connections: {}, Available: {}, Max: {}",
50+
status.size, status.available, status.max_size
51+
)
52+
})
53+
.collect::<Vec<String>>(),
54+
)
55+
.field(
56+
"https_pools",
57+
&self
58+
.http_pools
59+
.iter()
60+
.map(|pool| {
61+
let status = pool.status();
62+
format!(
63+
"Connections: {}, Available: {}, Max: {}",
64+
status.size, status.available, status.max_size
65+
)
66+
})
67+
.collect::<Vec<String>>(),
68+
)
69+
.field(
70+
"max_concurrent_connections",
71+
&self.max_concurrent_connections,
72+
)
73+
.finish()
4174
}
4275
}
4376

0 commit comments

Comments
 (0)