Skip to content

feat: enhance __str__ representation of types#567

Merged
0x676e67 merged 1 commit intomainfrom
fmt
Apr 14, 2026
Merged

feat: enhance __str__ representation of types#567
0x676e67 merged 1 commit intomainfrom
fmt

Conversation

@0x676e67
Copy link
Copy Markdown
Owner

@0x676e67 0x676e67 commented Apr 14, 2026

Summary by CodeRabbit

  • Refactor

    • Standardized display formatting implementation across multiple types for improved consistency in how objects are rendered when printed.
  • Examples

    • Updated the header map example to demonstrate full output display.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 14, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This pull request refactors the display/formatting macro implementation across the codebase. The define_display! macro is replaced with a new impl_print_str! macro in src/macros.rs, and all usages throughout the codebase are updated to use the new macro with an explicit trait parameter (Display or Debug). Additionally, an example file is updated to print a HeaderMap object.

Changes

Cohort / File(s) Summary
Example Output Update
examples/header_map.py
Added print(headers) statement to output the full HeaderMap after the emptiness check.
Macro Definition Refactoring
src/macros.rs
Replaced define_display! macro with impl_print_str! macro. New macro accepts a trait parameter (Debug or Display) and generates appropriate implementations: Debug delegates to std::fmt::Debug::fmt(&self.0, f), while Display delegates to self.0.fmt(f).
Client & Message Display Updates
src/client.rs, src/client/resp/ws/msg.rs
Updated display implementation from define_display! to impl_print_str!(Display, ...) for SocketAddr and Message types.
Core Type Display Updates
src/cookie.rs, src/http.rs
Updated Cookie and StatusCode display implementations from define_display! to impl_print_str!(Display, ...).
Header & Collection Debug Updates
src/header.rs
Changed HeaderMap and OrigHeaderMap from define_display! to impl_print_str!(Debug, ...), switching to debug-based string representation.
Configuration Type Debug Updates
src/http1.rs, src/proxy.rs, src/redirect.rs
Updated Http1Options, Proxy, Policy, and History from define_display! to impl_print_str!(Debug, ...) for debug-based formatting.
HTTP/2 Protocol Types
src/http2.rs
Updated six protocol-level types (StreamId, StreamDependency, Priority, Priorities, PseudoOrder, SettingsOrder) to use impl_print_str!(Display, ...), and Http2Options to use impl_print_str!(Debug, ...).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A macro hops where once it stood,
From define_display to prints so good,
With Debug and Display traits now clear,
The format dance brings debugging cheer! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: replacing display formatting macros with improved string representation implementations across multiple types.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fmt

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request replaces the define_display! macro with a more versatile impl_print_str! macro, allowing types to implement Display using either their inner type's Debug or Display implementation. Corresponding updates were made across several modules, and a print statement was added to the header_map.py example. A critical issue was identified in the impl_print_str! macro's Display branch, where calling self.0.fmt(f) may lead to compilation errors if the Display trait is not in scope; using the fully qualified path std::fmt::Display::fmt is suggested for better reliability.

@0x676e67 0x676e67 merged commit 8eff131 into main Apr 14, 2026
31 of 32 checks passed
@0x676e67 0x676e67 deleted the fmt branch April 14, 2026 11:45
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.

1 participant