pub trait Alloc {
type Error: From<Error> + Debug + Display;
// Required method
fn alloc(&self, layout: Layout) -> Result<NonNull<u8>, Self::Error>;
// Provided method
fn zalloc(&self, layout: Layout) -> Result<NonNull<u8>, Self::Error> { ... }
}Expand description
A memory allocation interface.
Required Associated Types§
Required Methods§
Sourcefn alloc(&self, layout: Layout) -> Result<NonNull<u8>, Self::Error>
fn alloc(&self, layout: Layout) -> Result<NonNull<u8>, Self::Error>
Attempts to allocate a block of memory fitting the given Layout.
Returns a dangling pointer if layout.size() ==
0.
§Errors
Errors are implementation-defined, refer to Self::Error and Error.
The standard implementations may return:
Err(Error::AllocFailed(layout, cause))if allocation fails.causeis typicallyCause::Unknown. If theos_err_reportingfeature is enabled, it will beCause::OSErr(oserr). In this case,oserrwill be the error fromIOErr::last_os_error.raw_os_error().
Provided Methods§
Sourcefn zalloc(&self, layout: Layout) -> Result<NonNull<u8>, Self::Error>
fn zalloc(&self, layout: Layout) -> Result<NonNull<u8>, Self::Error>
Attempts to allocate a zeroed block of memory fitting the given Layout.
Returns a dangling pointer if layout.size() ==
0.
§Errors
Errors are implementation-defined, refer to Self::Error and Error.
The standard implementations may return:
Err(Error::AllocFailed(layout, cause))if allocation fails.causeis typicallyCause::Unknown. If theos_err_reportingfeature is enabled, it will beCause::OSErr. In this case,oserrwill be the error fromIOErr::last_os_error.raw_os_error().