diff --git a/examples/header_map.py b/examples/header_map.py index 05b248f5..2bc43d1c 100644 --- a/examples/header_map.py +++ b/examples/header_map.py @@ -18,6 +18,8 @@ print("keys_len (unique keys):", headers.keys_len()) # Check if the map is empty print("is_empty:", headers.is_empty()) + # Print the entire header map + print(headers) # Clear all headers headers.clear() print("After clear, is_empty:", headers.is_empty()) diff --git a/src/client.rs b/src/client.rs index 6bb709f3..6da0938b 100644 --- a/src/client.rs +++ b/src/client.rs @@ -54,7 +54,7 @@ impl SocketAddr { } } -define_display!(SocketAddr); +impl_print_str!(Display, SocketAddr); /// A builder for `Client`. #[derive(Default)] diff --git a/src/client/resp/ws/msg.rs b/src/client/resp/ws/msg.rs index 44b2e47d..ceb5bfd2 100644 --- a/src/client/resp/ws/msg.rs +++ b/src/client/resp/ws/msg.rs @@ -173,4 +173,4 @@ impl Message { } } -define_display!(Message); +impl_print_str!(Display, Message); diff --git a/src/cookie.rs b/src/cookie.rs index 53580eed..324dc712 100644 --- a/src/cookie.rs +++ b/src/cookie.rs @@ -181,7 +181,7 @@ impl Cookie { } } -define_display!(Cookie); +impl_print_str!(Display, Cookie); // ===== impl Cookies ===== diff --git a/src/header.rs b/src/header.rs index a0f3f05e..bf8794f1 100644 --- a/src/header.rs +++ b/src/header.rs @@ -232,7 +232,7 @@ impl HeaderMap { } } -define_display!(HeaderMap); +impl_print_str!(Debug, HeaderMap); impl FromPyObject<'_, '_> for HeaderMap { type Error = PyErr; @@ -338,7 +338,7 @@ impl OrigHeaderMap { } } -define_display!(OrigHeaderMap); +impl_print_str!(Debug, OrigHeaderMap); impl FromPyObject<'_, '_> for OrigHeaderMap { type Error = PyErr; diff --git a/src/http.rs b/src/http.rs index c9cabb23..f79272d5 100644 --- a/src/http.rs +++ b/src/http.rs @@ -86,4 +86,4 @@ impl StatusCode { } } -define_display!(StatusCode); +impl_print_str!(Display, StatusCode); diff --git a/src/http1.rs b/src/http1.rs index cc51e8cd..cf84ab12 100644 --- a/src/http1.rs +++ b/src/http1.rs @@ -107,4 +107,4 @@ impl Http1Options { } } -define_display!(Http1Options); +impl_print_str!(Debug, Http1Options); diff --git a/src/http2.rs b/src/http2.rs index c9918fa6..60e49083 100644 --- a/src/http2.rs +++ b/src/http2.rs @@ -206,7 +206,7 @@ impl StreamId { } } -define_display!(StreamId); +impl_print_str!(Display, StreamId); // ===== impl StreamDependency ===== @@ -224,7 +224,7 @@ impl StreamDependency { } } -define_display!(StreamDependency); +impl_print_str!(Display, StreamDependency); // ===== impl Priority ===== @@ -238,7 +238,7 @@ impl Priority { } } -define_display!(Priority); +impl_print_str!(Display, Priority); // ===== impl Priorities ===== @@ -256,7 +256,7 @@ impl Priorities { } } -define_display!(Priorities); +impl_print_str!(Display, Priorities); // ===== impl PseudoOrder ===== @@ -274,7 +274,7 @@ impl PseudoOrder { } } -define_display!(PseudoOrder); +impl_print_str!(Display, PseudoOrder); // ===== impl SettingsOrder ===== @@ -292,7 +292,7 @@ impl SettingsOrder { } } -define_display!(SettingsOrder); +impl_print_str!(Display, SettingsOrder); // ===== impl Builder ===== @@ -462,4 +462,4 @@ impl Http2Options { } } -define_display!(Http2Options); +impl_print_str!(Debug, Http2Options); diff --git a/src/macros.rs b/src/macros.rs index 73f9c544..4aeab982 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -161,8 +161,8 @@ macro_rules! define_enum { }; } -macro_rules! define_display { - ($typed:ident) => { +macro_rules! impl_print_str { + (Debug, $typed:ident) => { impl std::fmt::Display for $typed { #[inline] fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { @@ -170,4 +170,12 @@ macro_rules! define_display { } } }; + (Display, $typed:ident) => { + impl std::fmt::Display for $typed { + #[inline] + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.0.fmt(f) + } + } + }; } diff --git a/src/proxy.rs b/src/proxy.rs index 1023d445..1277277b 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -93,7 +93,7 @@ impl Proxy { } } -define_display!(Proxy); +impl_print_str!(Debug, Proxy); fn create_proxy<'py>( py: Python<'py>, diff --git a/src/redirect.rs b/src/redirect.rs index 9476b87c..353f0555 100644 --- a/src/redirect.rs +++ b/src/redirect.rs @@ -126,7 +126,7 @@ impl Policy { } } -define_display!(Policy); +impl_print_str!(Debug, Policy); // ===== impl Attempt ===== @@ -196,4 +196,4 @@ impl Display for Action { // ===== impl History ===== -define_display!(History); +impl_print_str!(Debug, History);