Skip to content

Commit 2690aea

Browse files
committed
uefi-raw: add .octets() for most types
This aligns the API with the core::net API. We don't do it for IpAddress as `unsafe { addr.v4 }.octets()` or `unsafe { addr.v6 }.octets()` are sufficient.
1 parent 0a67eeb commit 2690aea

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

uefi-raw/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
- Added `PciRootBridgeIoProtocol`.
66
- Added `ConfigKeywordHandlerProtocol`.
77
- Added `HiiConfigAccessProtocol`.
8+
- Added `::octets()` for `Ipv4Address`, `Ipv6Address`, and
9+
`MacAddress` to streamline the API with `core::net`.
810

911
## Changed
1012
- The documentation for UEFI protocols has been streamlined and improved.

uefi-raw/src/net.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ use core::fmt::{Debug, Formatter};
1616
#[repr(transparent)]
1717
pub struct Ipv4Address(pub [u8; 4]);
1818

19+
impl Ipv4Address {
20+
/// Returns the octets of the IP address.
21+
#[must_use]
22+
pub const fn octets(self) -> [u8; 4] {
23+
self.0
24+
}
25+
}
26+
1927
impl From<core::net::Ipv4Addr> for Ipv4Address {
2028
fn from(ip: core::net::Ipv4Addr) -> Self {
2129
Self(ip.octets())
@@ -33,6 +41,14 @@ impl From<Ipv4Address> for core::net::Ipv4Addr {
3341
#[repr(transparent)]
3442
pub struct Ipv6Address(pub [u8; 16]);
3543

44+
impl Ipv6Address {
45+
/// Returns the octets of the IP address.
46+
#[must_use]
47+
pub const fn octets(self) -> [u8; 16] {
48+
self.0
49+
}
50+
}
51+
3652
impl From<core::net::Ipv6Addr> for Ipv6Address {
3753
fn from(ip: core::net::Ipv6Addr) -> Self {
3854
Self(ip.octets())
@@ -125,6 +141,15 @@ impl From<core::net::IpAddr> for IpAddress {
125141
#[repr(transparent)]
126142
pub struct MacAddress(pub [u8; 32]);
127143

144+
impl MacAddress {
145+
/// Returns the octets of the MAC address.
146+
#[must_use]
147+
pub const fn octets(self) -> [u8; 32] {
148+
self.0
149+
}
150+
}
151+
152+
// Normal/typical MAC addresses, such as in Ethernet.
128153
impl From<[u8; 6]> for MacAddress {
129154
fn from(octets: [u8; 6]) -> Self {
130155
let mut buffer = [0; 32];

0 commit comments

Comments
 (0)