pub unsafe trait AllocatedMemory:
Sized
+ PartialEq
+ Eq
+ Clone
+ Hash
+ Debug {
// Required methods
unsafe fn as_ptr(&self) -> *mut u8;
fn resize(
self,
old_layout: Layout,
new_layout: Layout,
) -> Result<Self, AllocationError>;
fn deallocate(self, layout: Layout);
}
Expand description
Represents a newly allocated piece of memory.
§Safety
Any type implementing this trait must ensure that the memory
is ultimately deallocated by calling AllocatedMemory::deallocate
.
Required Methods§
Sourceunsafe fn as_ptr(&self) -> *mut u8
unsafe fn as_ptr(&self) -> *mut u8
Converts the AllocatedMemory
into a raw pointer.
§Safety
This function is unsafe since it doesn’t move ownership, and so multiple copies of the same memory can exist.
Sourcefn resize(
self,
old_layout: Layout,
new_layout: Layout,
) -> Result<Self, AllocationError>
fn resize( self, old_layout: Layout, new_layout: Layout, ) -> Result<Self, AllocationError>
Resizes the AllocatedMemory
to a new layout.
§Errors
Returns an AllocationError
if the memory cannot be resized.
Sourcefn deallocate(self, layout: Layout)
fn deallocate(self, layout: Layout)
Deallocates the AllocatedMemory
.
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.