pub trait CheckedReallocMut: ReallocMut {
// Required methods
fn checked_realloc_mut(
&mut self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<u8>, <Self as AllocDescriptor>::Error>;
fn checked_rezalloc_mut(
&mut self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<u8>, <Self as AllocDescriptor>::Error>;
}Expand description
A memory allocation interface which can arbitrarily resize allocations safely, requiring mutable access.
Required Methods§
Sourcefn checked_realloc_mut(
&mut self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<u8>, <Self as AllocDescriptor>::Error>
fn checked_realloc_mut( &mut self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<u8>, <Self as AllocDescriptor>::Error>
Attempts to reallocate a previously allocated block after performing validity checks.
On grow, preserves existing contents up to
old_layout.size(), and on shrink, truncates to
new_layout.size().
On failure, the original memory will not be deallocated.
This method must return an error rather than silently accepting invalid inputs and potentially causing undefined behavior.
§Errors
Errors are implementation-defined, refer to AllocDescriptor::Error and Error.
The standard implementations may return:
Err(Error::Unsupported)if checked reallocation is unsupported.Err(Error::Other(err))for allocator-specific validation failures. If thealloc_mutfeature is enabled, and using this method on a synchronization primitive wrapping a type which implementsReallocMut, a generic error message will also be returned if locking the primitive fails.
Sourcefn checked_rezalloc_mut(
&mut self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<u8>, <Self as AllocDescriptor>::Error>
fn checked_rezalloc_mut( &mut self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<u8>, <Self as AllocDescriptor>::Error>
Attempts to reallocate a previously allocated block after performing validity checks, with extra bytes being zeroed.
On grow, preserves existing contents up to
old_layout.size(), and on shrink, truncates to
new_layout.size().
On failure, the original memory will not be deallocated.
This method must return an error rather than silently accepting invalid inputs and potentially causing undefined behavior.
§Errors
Errors are implementation-defined, refer to AllocDescriptor::Error and Error.
The standard implementations may return:
Err(Error::Unsupported)if checked reallocation is unsupported.Err(Error::Other(err))for allocator-specific validation failures. If thealloc_mutfeature is enabled, and using this method on a synchronization primitive wrapping a type which implementsReallocMut, a generic error message will also be returned if locking the primitive fails.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".