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
fn new_two_step() -> Self
Returns a new, empty instance of Self
.
unsafe fn deref_holder(&mut self) -> &mut Option<OWNED>
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
impl<T, B: ?Sized> TwoStepShared<T, B> for TwoStepRc<T, B> where T: SafeBorrow<B>
impl<T, B: ?Sized> TwoStepShared<T, B> for TwoStepArc<T, B> where T: SafeBorrow<B>
impl<'a, S: 'a + ?Sized, T: 'a> TwoStepShared<T, S> for Box<DefaultFeatures<'a> + 'a> where T: SafeBorrow<S>, TwoStepArc<T, S>: DefaultFeatures<'a>
impl<'a, S: 'a + ?Sized, T: 'a> TwoStepShared<T, S> for Box<NonSyncFeatures<'a> + 'a> where T: SafeBorrow<S>, TwoStepRc<T, S>: NonSyncFeatures<'a>