[−][src]Trait swim_mem::resident::Resident
A type that can reside in a raw, unsized memory block. A memory Resident
abstracts over the usage of a memory Lease
, which itself abstracts over
the allocation and ownership semantics of a raw, unsized memory block.
Requirements
Resident
implementation don't store data internally; they proxy all data
accesses through a passed-in Lease
, which acts as the de facto self
argument for all Resident
methods. A memory Lease
grants its Resident
temporary access to a data pointer, of type Data
, which may be a fat,
unsized pointer. A Lease
also provides its Resident
access to a sized
metadata pointer, of type Meta
.
A Lease
manages the lifetime, placement, and ownership semantics of its
data and metadata pointers. A Lease
may alias or relocate those pointers
at any time, so long as it doesn't violate Rust's borrowing semantics.
A Lease
delegates to its Resident
to determine the size and alignment
of any leased memory blocks; a Lease
cannot assume that the size of its
memory block equals the size of its Resident
's *Data
.
For example, a Box
uses the size of its pointed-to data
, possibly via
a dynamically sized fat pointer, as the size of its memory block. Whereas
a Buf
determines its memory block size by multiplying the static size
of its Data
type by a capacity value stored in the Lease
's associated
metadata. Abstracting over these size and usage patterns is the primary
reason for Resident
's existence.
Associated Types
type Data: ?Sized
The type of pointed-to data stored in leased memory blocks. The size of
leased memory blocks must be a positive multiple of the Data
size.
type Meta
The type of metadata stored with leased memory blocks. Meta
data must
contain sufficient information to resolve the size of any resided-in
memory Lease
.
Required methods
unsafe fn resident_size(data: *mut Self::Data, meta: *mut Self::Meta) -> usize
Returns the size in bytes of the Resident
with the given data
and meta
data.
unsafe fn resident_drop(data: *mut Self::Data, meta: *mut Self::Meta)
Drops the Resident
with the given data
and meta
data.