Skip to content

Commit 0a68863

Browse files
committed
uefi-raw: net: implement Display for Ipv4Address and Ipv6Address
1 parent ecf8f89 commit 0a68863

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

uefi-raw/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
- Added `::octets()` for `Ipv4Address`, `Ipv6Address`, and
99
`MacAddress` to streamline the API with `core::net`.
1010
- Added `::ZERO` constant for `IpAddress`
11+
- `Ipv4Address` and `Ipv6Address` now implement `Display`. They
12+
use the same formatting as `core::net::{Ipv4Addr, Ipv6Addr}`
1113

1214
## Changed
1315
- **Breaking:** The MSRV is now 1.85.1 and the crate uses the Rust 2024 edition.

uefi-raw/src/net.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//! - [`Ipv4Address`]
99
//! - [`Ipv6Address`]
1010
11-
use core::fmt::{self, Debug, Formatter};
11+
use core::fmt::{self, Debug, Display, Formatter};
1212

1313
/// An IPv4 internet protocol address.
1414
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
@@ -35,6 +35,13 @@ impl From<Ipv4Address> for core::net::Ipv4Addr {
3535
}
3636
}
3737

38+
impl Display for Ipv4Address {
39+
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
40+
let ip = core::net::Ipv4Addr::from(*self);
41+
write!(f, "{}", ip)
42+
}
43+
}
44+
3845
/// An IPv6 internet protocol address.
3946
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
4047
#[repr(transparent)]
@@ -60,6 +67,13 @@ impl From<Ipv6Address> for core::net::Ipv6Addr {
6067
}
6168
}
6269

70+
impl Display for Ipv6Address {
71+
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
72+
let ip = core::net::Ipv6Addr::from(*self);
73+
write!(f, "{}", ip)
74+
}
75+
}
76+
6377
/// An IPv4 or IPv6 internet protocol address that is ABI compatible with EFI.
6478
///
6579
/// Corresponds to the `EFI_IP_ADDRESS` type in the UEFI specification. This

0 commit comments

Comments
 (0)