-
-
Notifications
You must be signed in to change notification settings - Fork 81
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
Conversation
There was a problem hiding this 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.
defmt/src/impls/core_/net.rs
Outdated
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] | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
defmt/src/impls/core_/net.rs
Outdated
crate::write!( | ||
fmt, | ||
"{}.{}.{}.{}", | ||
self.octets()[0], | ||
self.octets()[1], | ||
self.octets()[2], | ||
self.octets()[3] | ||
); |
There was a problem hiding this comment.
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.
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}");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
Thank you! bors r+ |
Build succeeded: |
This adds formatting for
core::net
types.core::net
is currently unstable, so this is feature gated.