Trait supercow::ext::OwnedStorage [] [src]

pub unsafe trait OwnedStorage<A, B>: Default {
    fn allocate_a(&mut self, value: A) -> *mut ();
    fn allocate_b(&mut self, value: B) -> *mut ();
    unsafe fn get_ptr_a<'a>(&'a self, ptr: *mut ()) -> &'a A;
    unsafe fn get_ptr_b<'a>(&'a self, ptr: *mut ()) -> &'a B;
    unsafe fn get_mut_a<'a>(&'a mut self, ptr: *mut ()) -> &'a mut A;
    unsafe fn get_mut_b<'a>(&'a mut self, ptr: *mut ()) -> &'a mut B;
    unsafe fn deallocate_a(&mut self, ptr: *mut ());
    unsafe fn deallocate_b(&mut self, ptr: *mut ());
    unsafe fn deallocate_into_a(&mut self, ptr: *mut ()) -> A;
    unsafe fn deallocate_into_b(&mut self, ptr: *mut ()) -> B;
    fn is_internal_storage() -> bool;
}

Describes how an OWNED or SHARED value is stored in a Supercow.

All notes for *_b functions are the same as the corresponding *_a functions.

Unsafety

Supercow relies strongly on the contracts of the functions in this trait being implemented correctly.

No function may mutate the A or B values.

Required Methods

Allocates the given owned value.

self is a Default-initialised instance.

Returns a pointer with 2-byte alignment.

Unsafety

Behaviour is undefined if this call returns a pointer with incorrect alignment.

Behaviour is undefined if the returned value is an address inside self offset by more than MAX_INTERNAL_BORROW_DISPLACEMENT/2 (note division by two).

Behaviour is undefined if this returns a null pointer. (But the returned pointer does not need to actually point at anything.)

See allocate_a.

Extracts the immutable reference from the saved pointer and storage.

Unsafety

This call may assume that ptr is exactly a (2-byte-aligned) value it returned from allocate_a, and that self was initialised by a call to allocate_a.

See get_ptr_a.

Extracts the mutable reference from the saved pointer and storage.

Unsafety

This call may assume that ptr is exactly a (2-byte-aligned) value it returned from allocate_a and that self was initialised by a call to allocate_a.

See get_mut_a.

Releases any allocations that would not be released by Stored being dropped.

Unsafety

This call may assume that ptr is exactly a (2-byte-aligned) value it returned from allocate_a.

Once this function is called, the given ptr is considered invalid and any further use is undefined.

This call must not panic (assuming the input contract is satisfied).

See deallocate_b.

Like deallocate_a(), but also return the owned value.

See deallocate_into_a.

Returns whether this storage implementation ever causes the owned object to be stored internally to the Supercow.

Unsafety

Behaviour is undefined if this returns false but the owned value is stored within the Supercow.

Implementors