pub unsafe trait Slab {
// Required methods
fn base_ptr(&self) -> *const u8;
fn base_ptr_mut(&mut self) -> *mut u8;
fn size(&self) -> usize;
// Provided methods
fn as_maybe_uninit_bytes(&self) -> &[MaybeUninit<u8>] { ... }
fn as_maybe_uninit_bytes_mut(&mut self) -> &mut [MaybeUninit<u8>] { ... }
unsafe fn assume_initialized_as_bytes(&self) -> &[u8] ⓘ { ... }
unsafe fn assume_initialized_as_bytes_mut(&mut self) -> &mut [u8] ⓘ { ... }
unsafe fn assume_range_initialized_as_bytes<R>(&self, range: R) -> &[u8] ⓘ
where R: SliceIndex<[MaybeUninit<u8>], Output = [MaybeUninit<u8>]> { ... }
unsafe fn assume_range_initialized_as_bytes_mut<R>(
&mut self,
range: R,
) -> &mut [u8] ⓘ
where R: SliceIndex<[MaybeUninit<u8>], Output = [MaybeUninit<u8>]> { ... }
}Expand description
Represents a contiguous piece of a single allocation with some layout that is used as a data copying destination. May be wholly or partially uninitialized.
This trait is basically equivalent to implementing Deref/DerefMut with
Target = [MaybeUninit<u8>] in terms of safety requirements. It is a separate
trait for the extra flexibility having a trait we own provides: namely, the ability
to implement it on foreign types.
§Safety
Implementors of this trait must ensure these guarantees:
- The memory range represented by
base_ptrandsizemay be wholly or partially uninitialized base_ptrmust point to a valid, single allocation of at leastsizebytes.sizemust not be greater thanisize::MAX
Assume the lifetime of a shared borrow of self is named 'a:
base_ptrmust be valid for'abase_ptrmust not be mutably aliased for'a- It is necessary but not sufficient for this requirement that no outside mutable references may exist to its data, even if they are unused by user code.
Assume the lifetime of a mutable borrow of self is named 'a:
base_ptr_mutmust be valid for'abase_ptr_mutmust not be aliased at all for'a- It is necessary but not sufficient for this requirement that no outside references may exist to its data, even if they are unused by user code.
Also see the crate-level safety documentation.
Required Methods§
Sourcefn base_ptr(&self) -> *const u8
fn base_ptr(&self) -> *const u8
Get a pointer to the beginning of the allocation represented by self.
Sourcefn base_ptr_mut(&mut self) -> *mut u8
fn base_ptr_mut(&mut self) -> *mut u8
Get a pointer to the beginning of the allocation represented by self.
Provided Methods§
Sourcefn as_maybe_uninit_bytes(&self) -> &[MaybeUninit<u8>]
fn as_maybe_uninit_bytes(&self) -> &[MaybeUninit<u8>]
Interpret a portion of self as a slice of MaybeUninit<u8>. This is likely not
incredibly useful, you probably want to use Slab::as_maybe_uninit_bytes_mut
Sourcefn as_maybe_uninit_bytes_mut(&mut self) -> &mut [MaybeUninit<u8>]
fn as_maybe_uninit_bytes_mut(&mut self) -> &mut [MaybeUninit<u8>]
Interpret a portion of self as a mutable slice of MaybeUninit<u8>.
Sourceunsafe fn assume_initialized_as_bytes(&self) -> &[u8] ⓘ
unsafe fn assume_initialized_as_bytes(&self) -> &[u8] ⓘ
Interpret self as a byte slice. This assumes that all bytes
in self are initialized.
§Safety
Assuming that the safety guarantees for creating self were followed,
the only extra requirement for this to be safe is that all memory
within the range of self must be initialized. If any bytes within
this range are not initialized, using this function is instantly undefined
behavior, even if you do noting with the result.
Also see the crate-level Safety documentation for more.
Sourceunsafe fn assume_initialized_as_bytes_mut(&mut self) -> &mut [u8] ⓘ
unsafe fn assume_initialized_as_bytes_mut(&mut self) -> &mut [u8] ⓘ
Interpret self as a mutable byte slice. This assumes that all bytes
in self are initialized.
§Safety
Assuming that the safety guarantees for creating self were followed,
the only extra requirement for this to be safe is that all memory
within the range of self must be initialized. If any bytes within
this range are not initialized, using this function is instantly undefined
behavior, even if you do noting with the result.
Also see the crate-level Safety documentation for more.
Sourceunsafe fn assume_range_initialized_as_bytes<R>(&self, range: R) -> &[u8] ⓘ
unsafe fn assume_range_initialized_as_bytes<R>(&self, range: R) -> &[u8] ⓘ
Interpret a range of self as a byte slice. This assumes that all bytes
within range are initialized.
In the future, this will hopefully not be needed as this operation will be equivalent to
something like self.as_maybe_uninit_bytes_mut()[range].assume_init(), but the core/std
implementation for this is still being scaffolded.
§Safety
Assuming that the safety guarantees for creating self were followed,
the only extra requirement for this to be safe is that all memory
within range must be initialized. If any bytes within
this range are not initialized, using this function is instantly undefined
behavior, even if you do noting with the result.
Also see the crate-level Safety documentation for more.
Sourceunsafe fn assume_range_initialized_as_bytes_mut<R>(
&mut self,
range: R,
) -> &mut [u8] ⓘ
unsafe fn assume_range_initialized_as_bytes_mut<R>( &mut self, range: R, ) -> &mut [u8] ⓘ
Interpret a range of self as a mutable byte slice. This assumes that all bytes
within range are initialized.
In the future, this will hopefully not be needed as this operation will be equivalent to
something like self.as_maybe_uninit_bytes_mut()[range].assume_init(), but the core/std
implementation for this is still being scaffolded.
§Safety
Assuming that the safety guarantees for creating self were followed,
the only extra requirement for this to be safe is that all memory
within range must be initialized. If any bytes within
this range are not initialized, using this function is instantly undefined
behavior, even if you do noting with the result.
Also see the crate-level Safety documentation for more.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.