pub unsafe trait AllocatedMemory:
Sized
+ PartialEq
+ Eq
+ Clone
+ Hash
+ Debug {
// Required methods
unsafe fn as_ptr<T: Sized>(&self) -> *mut T;
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. Typically a thin wrapper
around raw *mut u8
pointer, but type safe.
§Safety
Any type implementing this trait must ensure that the memory
is ultimately deallocated by calling AllocatedMemory::deallocate
.
Required Methods§
Sourceunsafe fn as_ptr<T: Sized>(&self) -> *mut T
unsafe fn as_ptr<T: Sized>(&self) -> *mut T
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. Moreover it does not
validate the pointer, in particular it does not check whether it is
properly aligned for the type T
.
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.