Enum maybe_owned::MaybeOwnedMut
source · [−]pub enum MaybeOwnedMut<'a, T: 'a> {
Owned(T),
Borrowed(&'a mut T),
}
Expand description
This type is basically the same as MaybeOwned
,
but works with mutable references.
Note that while you can se MaybeOwned
as a alternative
implementation for a Cow (Copy-On-Write) type this isn’t
really the case for MaybeOwnedMut
as changing it will
potentially change the source through the given &mut
reference. For example the transitive add assign (+=)
implementation for MaybeOwned
does (need to) convert
the given instance into a owned variant before using
+=
on the contained type. But for MaybeOwnedMut
it
can directly use +=
on the &mut
contained in the
Borrowed
variant!
Variants
Owned(T)
owns T
Borrowed(&'a mut T)
has a reference to T
Implementations
sourceimpl<T> MaybeOwnedMut<'_, T>
impl<T> MaybeOwnedMut<'_, T>
sourceimpl<T: Clone> MaybeOwnedMut<'_, T>
impl<T: Clone> MaybeOwnedMut<'_, T>
sourcepub fn into_owned(self) -> T
pub fn into_owned(self) -> T
Return the contained data in it’s owned form.
If it’s borrowed this will clone it.
sourcepub fn make_owned(&mut self) -> &mut T
pub fn make_owned(&mut self) -> &mut T
Internally converts the type into it’s owned variant.
Conversion from a reference to the owned variant is done by cloning.
This returns a &mut T
and as such can be used to “unconditionally”
get an &mut T
. Be aware that while this works with both MaybeOwned
and MaybeOwnedMut
it also converts it to an owned variant in both
cases. So while it’s the best way to get a &mut T
for MaybeOwned
for MaybeOwnedMut
it’s preferable to use as_mut
from AsMut
.
Example
use maybe_owned::MaybeOwned;
#[derive(Clone, Debug, PartialEq, Eq)]
struct PseudoBigData(u8);
let data = PseudoBigData(12);
let mut maybe: MaybeOwned<PseudoBigData> = (&data).into();
assert_eq!(false, maybe.is_owned());
{
let reference = maybe.make_owned();
assert_eq!(&mut PseudoBigData(12), reference);
}
assert!(maybe.is_owned());
Trait Implementations
sourceimpl<'min, L, R, OUT: 'min> Add<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
L: Add<R, Output = OUT> + Add<&'min R, Output = OUT>,
&'min L: Add<R, Output = OUT> + Add<&'min R, Output = OUT>,
impl<'min, L, R, OUT: 'min> Add<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
L: Add<R, Output = OUT> + Add<&'min R, Output = OUT>,
&'min L: Add<R, Output = OUT> + Add<&'min R, Output = OUT>,
sourceimpl<'min, L, R> AddAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
L: AddAssign<R> + AddAssign<&'min R>,
impl<'min, L, R> AddAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
L: AddAssign<R> + AddAssign<&'min R>,
sourcefn add_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
fn add_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
Performs the +=
operation. Read more
sourceimpl<T> AsMut<T> for MaybeOwnedMut<'_, T>
impl<T> AsMut<T> for MaybeOwnedMut<'_, T>
sourceimpl<'min, L, R, OUT: 'min> BitAnd<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
L: BitAnd<R, Output = OUT> + BitAnd<&'min R, Output = OUT>,
&'min L: BitAnd<R, Output = OUT> + BitAnd<&'min R, Output = OUT>,
impl<'min, L, R, OUT: 'min> BitAnd<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
L: BitAnd<R, Output = OUT> + BitAnd<&'min R, Output = OUT>,
&'min L: BitAnd<R, Output = OUT> + BitAnd<&'min R, Output = OUT>,
sourceimpl<'min, L, R> BitAndAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
L: BitAndAssign<R> + BitAndAssign<&'min R>,
impl<'min, L, R> BitAndAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
L: BitAndAssign<R> + BitAndAssign<&'min R>,
sourcefn bitand_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
fn bitand_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
Performs the &=
operation. Read more
sourceimpl<'min, L, R, OUT: 'min> BitOr<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
L: BitOr<R, Output = OUT> + BitOr<&'min R, Output = OUT>,
&'min L: BitOr<R, Output = OUT> + BitOr<&'min R, Output = OUT>,
impl<'min, L, R, OUT: 'min> BitOr<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
L: BitOr<R, Output = OUT> + BitOr<&'min R, Output = OUT>,
&'min L: BitOr<R, Output = OUT> + BitOr<&'min R, Output = OUT>,
sourceimpl<'min, L, R> BitOrAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
L: BitOrAssign<R> + BitOrAssign<&'min R>,
impl<'min, L, R> BitOrAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
L: BitOrAssign<R> + BitOrAssign<&'min R>,
sourcefn bitor_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
fn bitor_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
Performs the |=
operation. Read more
sourceimpl<'min, L, R, OUT: 'min> BitXor<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
L: BitXor<R, Output = OUT> + BitXor<&'min R, Output = OUT>,
&'min L: BitXor<R, Output = OUT> + BitXor<&'min R, Output = OUT>,
impl<'min, L, R, OUT: 'min> BitXor<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
L: BitXor<R, Output = OUT> + BitXor<&'min R, Output = OUT>,
&'min L: BitXor<R, Output = OUT> + BitXor<&'min R, Output = OUT>,
sourceimpl<'min, L, R> BitXorAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
L: BitXorAssign<R> + BitXorAssign<&'min R>,
impl<'min, L, R> BitXorAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
L: BitXorAssign<R> + BitXorAssign<&'min R>,
sourcefn bitxor_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
fn bitxor_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
Performs the ^=
operation. Read more
sourceimpl<T> Borrow<T> for MaybeOwnedMut<'_, T>
impl<T> Borrow<T> for MaybeOwnedMut<'_, T>
sourceimpl<T> BorrowMut<T> for MaybeOwnedMut<'_, T>
impl<T> BorrowMut<T> for MaybeOwnedMut<'_, T>
sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<'a, T: Debug + 'a> Debug for MaybeOwnedMut<'a, T>
impl<'a, T: Debug + 'a> Debug for MaybeOwnedMut<'a, T>
sourceimpl<T: Default> Default for MaybeOwnedMut<'_, T>
impl<T: Default> Default for MaybeOwnedMut<'_, T>
sourceimpl<T> Deref for MaybeOwnedMut<'_, T>
impl<T> Deref for MaybeOwnedMut<'_, T>
sourceimpl<T> DerefMut for MaybeOwnedMut<'_, T>
impl<T> DerefMut for MaybeOwnedMut<'_, T>
sourceimpl<'a, T: Display> Display for MaybeOwnedMut<'a, T>
impl<'a, T: Display> Display for MaybeOwnedMut<'a, T>
sourceimpl<'min, L, R, OUT: 'min> Div<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
L: Div<R, Output = OUT> + Div<&'min R, Output = OUT>,
&'min L: Div<R, Output = OUT> + Div<&'min R, Output = OUT>,
impl<'min, L, R, OUT: 'min> Div<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
L: Div<R, Output = OUT> + Div<&'min R, Output = OUT>,
&'min L: Div<R, Output = OUT> + Div<&'min R, Output = OUT>,
sourceimpl<'min, L, R> DivAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
L: DivAssign<R> + DivAssign<&'min R>,
impl<'min, L, R> DivAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
L: DivAssign<R> + DivAssign<&'min R>,
sourcefn div_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
fn div_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
Performs the /=
operation. Read more
sourceimpl<'a, T> From<&'a mut T> for MaybeOwnedMut<'a, T>
impl<'a, T> From<&'a mut T> for MaybeOwnedMut<'a, T>
sourceimpl<T> From<T> for MaybeOwnedMut<'_, T>
impl<T> From<T> for MaybeOwnedMut<'_, T>
sourceimpl<T: FromStr> FromStr for MaybeOwnedMut<'_, T>
impl<T: FromStr> FromStr for MaybeOwnedMut<'_, T>
sourceimpl<T: Hash> Hash for MaybeOwnedMut<'_, T>
impl<T: Hash> Hash for MaybeOwnedMut<'_, T>
sourceimpl<'min, L, R, OUT: 'min> Mul<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
L: Mul<R, Output = OUT> + Mul<&'min R, Output = OUT>,
&'min L: Mul<R, Output = OUT> + Mul<&'min R, Output = OUT>,
impl<'min, L, R, OUT: 'min> Mul<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
L: Mul<R, Output = OUT> + Mul<&'min R, Output = OUT>,
&'min L: Mul<R, Output = OUT> + Mul<&'min R, Output = OUT>,
sourceimpl<'min, L, R> MulAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
L: MulAssign<R> + MulAssign<&'min R>,
impl<'min, L, R> MulAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
L: MulAssign<R> + MulAssign<&'min R>,
sourcefn mul_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
fn mul_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
Performs the *=
operation. Read more
sourceimpl<'l, V, OUT> Neg for MaybeOwnedMut<'l, V> where
V: Neg<Output = OUT>,
&'l V: Neg<Output = OUT>,
impl<'l, V, OUT> Neg for MaybeOwnedMut<'l, V> where
V: Neg<Output = OUT>,
&'l V: Neg<Output = OUT>,
sourceimpl<'l, V, OUT> Not for MaybeOwnedMut<'l, V> where
V: Not<Output = OUT>,
&'l V: Not<Output = OUT>,
impl<'l, V, OUT> Not for MaybeOwnedMut<'l, V> where
V: Not<Output = OUT>,
&'l V: Not<Output = OUT>,
sourceimpl<T: Ord> Ord for MaybeOwnedMut<'_, T>
impl<T: Ord> Ord for MaybeOwnedMut<'_, T>
sourceimpl<'b, A: PartialEq<B>, B> PartialEq<MaybeOwnedMut<'b, B>> for MaybeOwnedMut<'_, A>
impl<'b, A: PartialEq<B>, B> PartialEq<MaybeOwnedMut<'b, B>> for MaybeOwnedMut<'_, A>
sourceimpl<T: PartialOrd> PartialOrd<MaybeOwnedMut<'_, T>> for MaybeOwnedMut<'_, T>
impl<T: PartialOrd> PartialOrd<MaybeOwnedMut<'_, T>> for MaybeOwnedMut<'_, T>
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl<'min, L, R, OUT: 'min> Shl<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
L: Shl<R, Output = OUT> + Shl<&'min R, Output = OUT>,
&'min L: Shl<R, Output = OUT> + Shl<&'min R, Output = OUT>,
impl<'min, L, R, OUT: 'min> Shl<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
L: Shl<R, Output = OUT> + Shl<&'min R, Output = OUT>,
&'min L: Shl<R, Output = OUT> + Shl<&'min R, Output = OUT>,
sourceimpl<'min, L, R> ShlAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
L: ShlAssign<R> + ShlAssign<&'min R>,
impl<'min, L, R> ShlAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
L: ShlAssign<R> + ShlAssign<&'min R>,
sourcefn shl_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
fn shl_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
Performs the <<=
operation. Read more
sourceimpl<'min, L, R, OUT: 'min> Shr<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
L: Shr<R, Output = OUT> + Shr<&'min R, Output = OUT>,
&'min L: Shr<R, Output = OUT> + Shr<&'min R, Output = OUT>,
impl<'min, L, R, OUT: 'min> Shr<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
L: Shr<R, Output = OUT> + Shr<&'min R, Output = OUT>,
&'min L: Shr<R, Output = OUT> + Shr<&'min R, Output = OUT>,
sourceimpl<'min, L, R> ShrAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
L: ShrAssign<R> + ShrAssign<&'min R>,
impl<'min, L, R> ShrAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
L: ShrAssign<R> + ShrAssign<&'min R>,
sourcefn shr_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
fn shr_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
Performs the >>=
operation. Read more
sourceimpl<'min, L, R, OUT: 'min> Sub<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
L: Sub<R, Output = OUT> + Sub<&'min R, Output = OUT>,
&'min L: Sub<R, Output = OUT> + Sub<&'min R, Output = OUT>,
impl<'min, L, R, OUT: 'min> Sub<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
L: Sub<R, Output = OUT> + Sub<&'min R, Output = OUT>,
&'min L: Sub<R, Output = OUT> + Sub<&'min R, Output = OUT>,
sourceimpl<'min, L, R> SubAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
L: SubAssign<R> + SubAssign<&'min R>,
impl<'min, L, R> SubAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
L: SubAssign<R> + SubAssign<&'min R>,
sourcefn sub_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
fn sub_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
Performs the -=
operation. Read more
impl<'a, T: Eq> Eq for MaybeOwnedMut<'a, T>
Auto Trait Implementations
impl<'a, T> RefUnwindSafe for MaybeOwnedMut<'a, T> where
T: RefUnwindSafe,
impl<'a, T> Send for MaybeOwnedMut<'a, T> where
T: Send,
impl<'a, T> Sync for MaybeOwnedMut<'a, T> where
T: Sync,
impl<'a, T> Unpin for MaybeOwnedMut<'a, T> where
T: Unpin,
impl<'a, T> !UnwindSafe for MaybeOwnedMut<'a, T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more