Skip to content

Commit dc25f62

Browse files
committed
uefi-raw: add as_ptr() and as_mut_ptr() for IpAddress
In a nutshell, IpAddress is a buffer for Ipv4 or Ipv6 addresses. As UEFI functions consume pointers, having this helper is very convenient, especially in `uefi/src/proto/network/pxe.rs`. The IpAddress type we want to replace in `uefi` with the more mature base version from `uefi-raw` also has corresponding helpers. This also aligns with other data structures that act as a buffer.
1 parent 8fc2097 commit dc25f62

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

uefi-raw/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- `[u8; 16]` --> `Ipv6Address`, `IpAddress`
1919
- Added `::into_core_ip_addr()` for `IpAddress`
2020
- Added `::try_into_ethernet_mac_addr()` for `MacAddress`
21+
- Added `::as_ptr()` and `::as_mut_ptr()` for `IpAddress`
2122

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

uefi-raw/src/net.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,16 @@ impl IpAddress {
165165
core::net::IpAddr::V4(core::net::Ipv4Addr::from(unsafe { self.v4.octets() }))
166166
}
167167
}
168+
169+
/// Returns a const pointer to the underlying buffer.
170+
pub fn as_ptr(&self) -> *const Self {
171+
&raw const *self
172+
}
173+
174+
/// Returns a mutable pointer to the underlying buffer.
175+
pub fn as_mut_ptr(&self) -> *const Self {
176+
&raw const *self
177+
}
168178
}
169179

170180
impl Debug for IpAddress {

0 commit comments

Comments
 (0)