[][src]Enum maybe_owned::MaybeOwnedMut

pub enum MaybeOwnedMut<'a, T: 'a> {
    Owned(T),
    Borrowed(&'a mut T),
}

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

impl<'_, T> MaybeOwnedMut<'_, T>[src]

pub fn is_owned(&self) -> bool[src]

Returns true if the data is owned else false.

impl<'_, T: Clone> MaybeOwnedMut<'_, T>[src]

pub fn into_owned(self) -> T[src]

Return the contained data in it's owned form.

If it's borrowed this will clone it.

pub fn make_owned(&mut self) -> &mut T[src]

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

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>, 
[src]

type Output = OUT

The resulting type after applying the + operator.

impl<'min, L, R> AddAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
    L: AddAssign<R> + AddAssign<&'min R>, 
[src]

impl<'_, T> AsMut<T> for MaybeOwnedMut<'_, T>[src]

impl<'_, T> AsRef<T> for MaybeOwnedMut<'_, T>[src]

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>, 
[src]

type Output = OUT

The resulting type after applying the & operator.

impl<'min, L, R> BitAndAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
    L: BitAndAssign<R> + BitAndAssign<&'min R>, 
[src]

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>, 
[src]

type Output = OUT

The resulting type after applying the | operator.

impl<'min, L, R> BitOrAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
    L: BitOrAssign<R> + BitOrAssign<&'min R>, 
[src]

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>, 
[src]

type Output = OUT

The resulting type after applying the ^ operator.

impl<'min, L, R> BitXorAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
    L: BitXorAssign<R> + BitXorAssign<&'min R>, 
[src]

impl<'_, T> Borrow<T> for MaybeOwnedMut<'_, T>[src]

impl<'_, T> BorrowMut<T> for MaybeOwnedMut<'_, T>[src]

impl<'a, T: Debug + 'a> Debug for MaybeOwnedMut<'a, T>[src]

impl<'_, T: Default> Default for MaybeOwnedMut<'_, T>[src]

impl<'_, T> Deref for MaybeOwnedMut<'_, T>[src]

type Target = T

The resulting type after dereferencing.

impl<'_, T> DerefMut for MaybeOwnedMut<'_, T>[src]

impl<'a, T: Display> Display for MaybeOwnedMut<'a, T>[src]

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>, 
[src]

type Output = OUT

The resulting type after applying the / operator.

impl<'min, L, R> DivAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
    L: DivAssign<R> + DivAssign<&'min R>, 
[src]

impl<'a, T: Eq> Eq for MaybeOwnedMut<'a, T>[src]

impl<'a, T> From<&'a mut T> for MaybeOwnedMut<'a, T>[src]

impl<'_, T> From<T> for MaybeOwnedMut<'_, T>[src]

impl<'_, T: FromStr> FromStr for MaybeOwnedMut<'_, T>[src]

type Err = T::Err

The associated error which can be returned from parsing.

impl<'_, T: Hash> Hash for MaybeOwnedMut<'_, T>[src]

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>, 
[src]

type Output = OUT

The resulting type after applying the * operator.

impl<'min, L, R> MulAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
    L: MulAssign<R> + MulAssign<&'min R>, 
[src]

impl<'l, V, OUT> Neg for MaybeOwnedMut<'l, V> where
    V: Neg<Output = OUT>,
    &'l V: Neg<Output = OUT>, 
[src]

type Output = OUT

The resulting type after applying the - operator.

impl<'l, V, OUT> Not for MaybeOwnedMut<'l, V> where
    V: Not<Output = OUT>,
    &'l V: Not<Output = OUT>, 
[src]

type Output = V::Output

The resulting type after applying the ! operator.

impl<'_, T: Ord> Ord for MaybeOwnedMut<'_, T>[src]

impl<'b, '_, A: PartialEq<B>, B> PartialEq<MaybeOwnedMut<'b, B>> for MaybeOwnedMut<'_, A>[src]

impl<'_, T: PartialOrd> PartialOrd<MaybeOwnedMut<'_, T>> for MaybeOwnedMut<'_, T>[src]

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>, 
[src]

type Output = OUT

The resulting type after applying the << operator.

impl<'min, L, R> ShlAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
    L: ShlAssign<R> + ShlAssign<&'min R>, 
[src]

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>, 
[src]

type Output = OUT

The resulting type after applying the >> operator.

impl<'min, L, R> ShrAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
    L: ShrAssign<R> + ShrAssign<&'min R>, 
[src]

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>, 
[src]

type Output = OUT

The resulting type after applying the - operator.

impl<'min, L, R> SubAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L> where
    L: SubAssign<R> + SubAssign<&'min R>, 
[src]

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<!> for T[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.