Skip to main content

ReservationParts

Struct ReservationParts 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§ptr: *mut u8

The base pointer of the reservation (from Reservation::reservation_ptr).

§len: usize

The length of the reservation in bytes (from Reservation::reservation_len).

§align: usize

The alignment requested at reservation time.

Implementations§

Source§

impl ReservationParts

Source

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.

Source

pub const fn as_tuple(self) -> (*mut u8, usize, usize)

Convert this struct back into a raw tuple compatible with release.

This method exists only for backwards compatibility with code that already uses the tuple form. New code should use release_parts instead.

Trait Implementations§

Source§

impl Debug for ReservationParts

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for ReservationParts

Source§

impl PartialEq for ReservationParts

Source§

fn eq(&self, other: &ReservationParts) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Send for ReservationParts

Source§

impl StructuralPartialEq for ReservationParts

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.