pub enum Shareable<T> {
Owned(T),
Shared(Arc<T>),
}
Expand description
Wraps an object and provides mutable access to it.
The point is that sometimes we want to stop mutability and proliferate reference-counted pointers to it.
This happens in a controlled environment, in the with_shared
method closure argument.
All reference-counted pointers are expected to be dropped until that closure finishes.
Variants§
Owned(T)
Implementations§
pub fn new(t: T) -> Self
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Destroys the object and returns the contents.
The main functionality of Shared
.
Temporarily makes the object immutable, and creates a Rc pointer to the contents, which can then be cloned.
Important restriction: all Rc pointers creates from the one given to the closure f
must be dropped before its execution ends.
Otherwise the operation will panic.
Trait Implementations§
Auto Trait Implementations§
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more