#[non_exhaustive]pub struct ReservationParts {
pub ptr: *mut u8,
pub len: usize,
pub align: usize,
}Expand description
The components returned by Reservation::into_reservation_parts.
A named structure (instead of a raw tuple) prevents the footgun of
accidentally swapping the len and align fields, which would be
undefined behavior on the native backend and cause leaks or crashes
on the Unix backend.
ReservationParts::new closes the release_parts round-trip (release a
reservation you only have the parts for). Reconstructing a full
Reservation via from_raw_parts additionally requires the usable base,
len, and granted_huge fields, which the caller must record separately —
ReservationParts alone is insufficient whenever the reservation was
over-reserved for alignment or when huge-page status must be preserved.
If you omit granted_huge, the reconstructed reservation will incorrectly
report is_huge() == false even if the original reservation used huge pages.
This struct holds the ONLY information that can free the underlying OS
reservation (task #1213/L3) — a plain drop of a ReservationParts
(letting it go out of scope without ever calling
release_parts or reconstructing a full
Reservation) silently leaks the mapping: this
struct has no Drop impl of its own. #[must_use] here catches an
ACCIDENTALLY discarded ownership token (e.g. a call to
Reservation::into_reservation_parts
whose result is never bound to anything) at compile time; it does not
and cannot prevent a DELIBERATE leak (e.g. binding the result to _ or
storing it and then dropping it later without acting on it).
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.ptr: *mut u8The base pointer of the reservation (from Reservation::reservation_ptr).
len: usizeThe length of the reservation in bytes (from Reservation::reservation_len).
align: usizeThe alignment requested at reservation time.
Implementations§
Source§impl ReservationParts
impl ReservationParts
Sourcepub const fn new(ptr: *mut u8, len: usize, align: usize) -> Self
pub const fn new(ptr: *mut u8, len: usize, align: usize) -> Self
Construct a ReservationParts from its component fields.
This closes the release_parts round-trip (release a reservation you
only have the parts for). Reconstructing a full Reservation via
from_raw_parts additionally requires the usable base, len, and
granted_huge fields, which the caller must record separately —
ReservationParts alone is insufficient whenever the reservation was
over-reserved for alignment or when huge-page status must be preserved.
No message-less #[must_use] on this function itself (task
#1213/L3): it returns Self, and the type now carries its own
#[must_use] with a leak-specific message — a redundant message-less
attribute on top of that is exactly what clippy’s double_must_use
lint rejects.