Trait StaticAllocator

pub unsafe trait StaticAllocator: Allocator

Marks that an allocator and its supertypes will never invalidate currently allocated memory unless explicitly deallocated via a call to a deallocating method, even if dropped or if the allocator's lifetime expires.

This is a necessity in conjunction with Pin, as only allocators that promise memory is never reused without a destructor running may be used to back a pinned pointer.

Safety

Implementors must ensure that memory blocks are only, ever invalidated by a call to a de/reallocating method on Allocator, and that this holds true for all possible instances of all subtypes of the implementor as well.

These requirements trivially apply to allocators that always maintain global state, such as System or Global. However, due to subtype coercion, it is not sound to implement for an arbitrary Allocator + 'static due to edge-case interactions with e.g. Pin::clone. Namely, an impl of StaticAllocator for MyAllocator + 'long guarantees that any value of MyAllocator + 'short also fulfills the requirements of StaticAllocator.

The following must thus be guaranteed:

Implementors