Skip to main content

AllocTemp

Trait AllocTemp 

Source
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§

Source

type Error: From<Error> + Debug + Display

The error type returned by this allocator.

Required Methods§

Source

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:

§Safety

Safety preconditions are implementation defined.

Provided Methods§

Source

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:

§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.

Implementors§