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§
Implementations§
source§impl<T> MaybeOwnedMut<'_, T>
impl<T> MaybeOwnedMut<'_, T>
source§impl<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§
source§impl<'min, L, R, OUT: 'min> Add<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
impl<'min, L, R, OUT: 'min> Add<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
source§impl<'min, L, R> AddAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
impl<'min, L, R> AddAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
source§fn add_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
fn add_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
+=
operation. Read moresource§impl<T> AsMut<T> for MaybeOwnedMut<'_, T>
impl<T> AsMut<T> for MaybeOwnedMut<'_, T>
source§impl<T> AsRef<T> for MaybeOwnedMut<'_, T>
impl<T> AsRef<T> for MaybeOwnedMut<'_, T>
source§impl<'min, L, R, OUT: 'min> BitAnd<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
impl<'min, L, R, OUT: 'min> BitAnd<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
source§impl<'min, L, R> BitAndAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
impl<'min, L, R> BitAndAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
source§fn bitand_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
fn bitand_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
&=
operation. Read moresource§impl<'min, L, R, OUT: 'min> BitOr<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
impl<'min, L, R, OUT: 'min> BitOr<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
source§impl<'min, L, R> BitOrAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
impl<'min, L, R> BitOrAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
source§fn bitor_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
fn bitor_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
|=
operation. Read moresource§impl<'min, L, R, OUT: 'min> BitXor<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
impl<'min, L, R, OUT: 'min> BitXor<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
source§impl<'min, L, R> BitXorAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
impl<'min, L, R> BitXorAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
source§fn bitxor_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
fn bitxor_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
^=
operation. Read moresource§impl<T> Borrow<T> for MaybeOwnedMut<'_, T>
impl<T> Borrow<T> for MaybeOwnedMut<'_, T>
source§impl<T> BorrowMut<T> for MaybeOwnedMut<'_, T>
impl<T> BorrowMut<T> for MaybeOwnedMut<'_, T>
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<'a, T: Debug + 'a> Debug for MaybeOwnedMut<'a, T>
impl<'a, T: Debug + 'a> Debug for MaybeOwnedMut<'a, T>
source§impl<T: Default> Default for MaybeOwnedMut<'_, T>
impl<T: Default> Default for MaybeOwnedMut<'_, T>
source§impl<T> Deref for MaybeOwnedMut<'_, T>
impl<T> Deref for MaybeOwnedMut<'_, T>
source§impl<T> DerefMut for MaybeOwnedMut<'_, T>
impl<T> DerefMut for MaybeOwnedMut<'_, T>
source§impl<'a, T: Display> Display for MaybeOwnedMut<'a, T>
impl<'a, T: Display> Display for MaybeOwnedMut<'a, T>
source§impl<'min, L, R, OUT: 'min> Div<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
impl<'min, L, R, OUT: 'min> Div<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
source§impl<'min, L, R> DivAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
impl<'min, L, R> DivAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
source§fn div_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
fn div_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
/=
operation. Read moresource§impl<'a, T> From<&'a mut T> for MaybeOwnedMut<'a, T>
impl<'a, T> From<&'a mut T> for MaybeOwnedMut<'a, T>
source§impl<T> From<T> for MaybeOwnedMut<'_, T>
impl<T> From<T> for MaybeOwnedMut<'_, T>
source§impl<T: FromStr> FromStr for MaybeOwnedMut<'_, T>
impl<T: FromStr> FromStr for MaybeOwnedMut<'_, T>
source§impl<T: Hash> Hash for MaybeOwnedMut<'_, T>
impl<T: Hash> Hash for MaybeOwnedMut<'_, T>
source§impl<'min, L, R, OUT: 'min> Mul<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
impl<'min, L, R, OUT: 'min> Mul<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
source§impl<'min, L, R> MulAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
impl<'min, L, R> MulAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
source§fn mul_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
fn mul_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
*=
operation. Read moresource§impl<'l, V, OUT> Neg for MaybeOwnedMut<'l, V>
impl<'l, V, OUT> Neg for MaybeOwnedMut<'l, V>
source§impl<'l, V, OUT> Not for MaybeOwnedMut<'l, V>
impl<'l, V, OUT> Not for MaybeOwnedMut<'l, V>
source§impl<T: Ord> Ord for MaybeOwnedMut<'_, T>
impl<T: Ord> Ord for MaybeOwnedMut<'_, T>
source§impl<'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>
source§impl<T: PartialOrd> PartialOrd for MaybeOwnedMut<'_, T>
impl<T: PartialOrd> PartialOrd for MaybeOwnedMut<'_, T>
source§impl<'min, L, R, OUT: 'min> Shl<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
impl<'min, L, R, OUT: 'min> Shl<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
source§impl<'min, L, R> ShlAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
impl<'min, L, R> ShlAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
source§fn shl_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
fn shl_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
<<=
operation. Read moresource§impl<'min, L, R, OUT: 'min> Shr<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
impl<'min, L, R, OUT: 'min> Shr<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
source§impl<'min, L, R> ShrAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
impl<'min, L, R> ShrAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
source§fn shr_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
fn shr_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
>>=
operation. Read moresource§impl<'min, L, R, OUT: 'min> Sub<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
impl<'min, L, R, OUT: 'min> Sub<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
source§impl<'min, L, R> SubAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
impl<'min, L, R> SubAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
source§fn sub_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
fn sub_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
-=
operation. Read more