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

defmt: add impl for core::net #733

Merged
merged 1 commit into from
Mar 7, 2023
Merged

defmt: add impl for core::net #733

merged 1 commit into from
Mar 7, 2023

Conversation

newAM
Copy link
Member

@newAM newAM commented Mar 5, 2023

This adds formatting for core::net types. core::net is currently unstable, so this is feature gated.

Copy link
Member

@Urhengulas Urhengulas left a comment

Choose a reason for hiding this comment

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

One small question and one suggestion; otherwise, it looks good.

Comment on lines 30 to 48
impl Format for net::Ipv6Addr {
fn format(&self, fmt: Formatter) {
crate::write!(
fmt,
"{:x}:{:x}:{:x}:{:x}:{:x}:{:x}:{:x}:{:x}",
self.octets()[0],
self.octets()[1],
self.octets()[2],
self.octets()[3],
self.octets()[4],
self.octets()[5],
self.octets()[6],
self.octets()[7]
);
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Ipv6Addr::octets(&self) returns a [u8; 16] (docs). Are you purposefully just using the first eight?

Copy link
Member Author

Choose a reason for hiding this comment

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

Whoops, that's a mistake on my part, good catch, thanks!

Comment on lines 13 to 20
crate::write!(
fmt,
"{}.{}.{}.{}",
self.octets()[0],
self.octets()[1],
self.octets()[2],
self.octets()[3]
);
Copy link
Member

Choose a reason for hiding this comment

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

You could also do the following. You don't have to; I just find it pretty.

Suggested change
crate::write!(
fmt,
"{}.{}.{}.{}",
self.octets()[0],
self.octets()[1],
self.octets()[2],
self.octets()[3]
);
let [a, b, c, d] = ip.octets();
crate::write!(fmt, "{}.{}.{}.{}", a, b, c, d);

With println! you could even do following, but unfortunately we didn't implement that (yet):

let [a, b, c, d] = ip.octets();
println!("{a}.{b}.{c}.{d}");

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

@Urhengulas
Copy link
Member

Thank you!

bors r+

@bors
Copy link
Contributor

bors bot commented Mar 7, 2023

Build succeeded:

@bors bors bot merged commit d6ce788 into knurling-rs:main Mar 7, 2023
@newAM newAM deleted the ip_in_core branch March 7, 2023 20:36
bors bot added a commit that referenced this pull request Mar 13, 2023
740: Snapshot tests for `core::net` r=Urhengulas a=Urhengulas

This PR adds snapshot tests for the implements added in #733. While doing that, I also clean up a bit.

Co-authored-by: Urhengulas <johann.hemmann@code.berlin>
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