pub trait Alloc: AllocErrorType + AllocMut {
// Required method
fn alloc(
&self,
layout: Layout,
) -> Result<NonNull<u8>, <Self as AllocErrorType>::Error>;
// Provided method
fn zalloc(
&self,
layout: Layout,
) -> Result<NonNull<u8>, <Self as AllocErrorType>::Error> { ... }
}Expand description
A memory allocation interface.
Required Methods§
Sourcefn alloc(
&self,
layout: Layout,
) -> Result<NonNull<u8>, <Self as AllocErrorType>::Error>
fn alloc( &self, layout: Layout, ) -> Result<NonNull<u8>, <Self as AllocErrorType>::Error>
Attempts to allocate a block of memory fitting the given Layout.
§Errors
Errors are implementation-defined, refer to AllocErrorType::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 fromlast_os_error().raw_os_error().Err(Error::ZeroSizedLayout)iflayout.size() == 0.
Provided Methods§
Sourcefn zalloc(
&self,
layout: Layout,
) -> Result<NonNull<u8>, <Self as AllocErrorType>::Error>
fn zalloc( &self, layout: Layout, ) -> Result<NonNull<u8>, <Self as AllocErrorType>::Error>
Attempts to allocate a zeroed block of memory fitting the given Layout.
§Errors
Errors are implementation-defined, refer to AllocErrorType::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 fromlast_os_error().raw_os_error().Err(Error::ZeroSizedLayout)iflayout.size() == 0.