maitake::task

Trait Storage

Source
pub trait Storage<S, F: Future>: Sized {
    type StoredTask;

    // Required methods
    fn into_raw(task: Self::StoredTask) -> NonNull<Task<S, F, Self>>;
    fn from_raw(ptr: NonNull<Task<S, F, Self>>) -> Self::StoredTask;
}
Expand description

A trait representing a heap allocation that can own a Task.

This is used to contain tasks at runtime, and abstract over the type erasure and type recovery steps, e.g. converting a heap allocation type into a NonNull pointer, and recovering it back into a heap allocation from a NonNull pointer

This trait is exposed publicly to allow for end users to implement for their own heap allocation types, if tasks must be stored in an allocation type other than Box.

This trait is ONLY appropriate for heap allocation types that represent exclusive ownership of the contained data, as it may be mutated while in pointer form. For example, the Box type would match this guarantee, but the Arc type would not, as it allows for shared access, and NOT exclusive mutable access.

Note: The type that implements this trait is typically NOT the heap allocation type itself, but a “Marker Type” that represents the intended storage medium. See the BoxStorage type (available with the “alloc” feature active) for an implementation example

Required Associated Types§

Source

type StoredTask

The type of a stored Task.

As the type that implements the Storage trait is a Marker Type, This associated type is the actual heap type that will be used to contain the Task.

Required Methods§

Source

fn into_raw(task: Self::StoredTask) -> NonNull<Task<S, F, Self>>

Convert an owned, heap-allocated Task type to a raw pointer

This method should produce a NonNull pointer, while not actually dropping the contained task.

Source

fn from_raw(ptr: NonNull<Task<S, F, Self>>) -> Self::StoredTask

Convert a raw task pointer into an owned, heapallocated [Task`] type

This method should produce a heap-allocated type, which can be dropped to perform the correct destructor actions

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§