pub trait AllocTemp {
type Error: From<Error> + Debug + Display;
// Required method
unsafe fn alloc_temp<R, F: FnOnce(NonNull<u8>) -> R>(
&self,
layout: Layout,
with_mem: F,
) -> Result<R, Self::Error>;
// Provided method
unsafe fn zalloc_temp<R, F: FnOnce(NonNull<u8>) -> R>(
&self,
layout: Layout,
with_mem: F,
) -> Result<R, Self::Error> { ... }
}Expand description
A memory allocation interface which may only be able to provide temporary, scoped allocations.
Required Associated Types§
Required Methods§
Sourceunsafe fn alloc_temp<R, F: FnOnce(NonNull<u8>) -> R>(
&self,
layout: Layout,
with_mem: F,
) -> Result<R, Self::Error>
unsafe fn alloc_temp<R, F: FnOnce(NonNull<u8>) -> R>( &self, layout: Layout, with_mem: F, ) -> Result<R, Self::Error>
Attempts to allocate a block of memory fitting the given Layout, and calls with_mem on
the returned pointer on success.
§Errors
Errors are implementation-defined, refer to AllocTemp::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.Err(Error::CaughtUnwind)if thecatch_unwindfeature is enabled and an unwind occurs in a function which is not allowed to unwind.
§Safety
Safety preconditions are implementation defined.
Provided Methods§
Sourceunsafe fn zalloc_temp<R, F: FnOnce(NonNull<u8>) -> R>(
&self,
layout: Layout,
with_mem: F,
) -> Result<R, Self::Error>
unsafe fn zalloc_temp<R, F: FnOnce(NonNull<u8>) -> R>( &self, layout: Layout, with_mem: F, ) -> Result<R, Self::Error>
Attempts to allocate a block of zeroed memory fitting the given Layout, and calls
with_mem on the returned pointer on success.
§Errors
Errors are implementation-defined, refer to AllocTemp::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.Err(Error::CaughtUnwind)if thecatch_unwindfeature is enabled and an unwind occurs in a function which is not allowed to unwind.
§Safety
Safety preconditions are implementation defined.
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.