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

Migrate fmt to use Display trait #44

Merged
merged 1 commit into from
Feb 10, 2025
Merged

Migrate fmt to use Display trait #44

merged 1 commit into from
Feb 10, 2025

Conversation

arnaucube
Copy link
Collaborator

Migrate fmt to use Display trait to simplify the usage of it.

Also with this, in the same snipped of code we can print types from backend, middleware and frontend; which before needed to import the two different Printer structs (frontend::Printer and mock_main::Printer).

Before:

let printer = mock_main::Printer { skip_none: false };
let mut w = io::stdout();
printer.fmt_mock_main_pod(&mut w, &pod).unwrap();

let printer = frontend::Printer { skip_none: false };
printer.fmt_main_pod_builder(&mut w, &pod_builder).unwrap();

now:

println!("{:#}", pod);
println!("{:#}", pod_builder);

And the equivalent to the old skip_none: true, now is done by just using `println!("{}", pod);

@arnaucube arnaucube requested review from ed255 and ax0 February 7, 2025 16:22
Copy link
Collaborator

@ed255 ed255 left a comment

Choose a reason for hiding this comment

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

Very nice!

Migrate fmt to use Display trait to simplify the usage of it.

Also with this, in the same snipped of code we can print types from
backend, middleware and frontend; which before needed to import the two
different `Printer` structs (frontend::Printer and mock_main::Printer).

Before:
```
let printer = mock_main::Printer { skip_none: false };
let mut w = io::stdout();
printer.fmt_mock_main_pod(&mut w, &pod).unwrap();

let printer = frontend::Printer { skip_none: false };
printer.fmt_main_pod_builder(&mut w, &pod_builder).unwrap();
```

now:
```
println!("{:#}", pod);
println!("{:#}", pod_builder);
```

And the equivalent to the old `skip_none: true`, now is done by just
using `println!("{}", pod);
@arnaucube arnaucube force-pushed the migrate-Display-trait branch from 40e7051 to 36aa5f0 Compare February 10, 2025 11:20
@ed255 ed255 merged commit 5236b46 into main Feb 10, 2025
1 check passed
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.

2 participants