Trait supercow::ext::TwoStepShared [] [src]

pub trait TwoStepShared<OWNED, BORROWED: ?Sized> {
    fn new_two_step() -> Self;
    unsafe fn deref_holder(&mut self) -> &mut Option<OWNED>;
}

Trait for ConstDeref implementations which can be constructed in a two-step process.

This is used by Supercow to safely promote owned values to shared values. A two-step process is necessary because the implementation must atomically transfer ownership of the value and so must set everything up first in case setup panics.

Essentially, such shared references actually hold an Option<Target> which defaults to None, and panic if dereferenced before the value is set.

Required Methods

Returns a new, empty instance of Self.

Returns the internal Option<T> backing this value.

Unsafety

This call may assume that self was produced by a call to new_two_step on the same implementation. (This is to allow downcasting without requiring Any which in turn requires 'static.)

The address of the value inside Some may not be altered by the implementation.

Implementors