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

Returns true if the data is owned else false.

Return the contained data in it’s owned form.

If it’s borrowed this will clone it.

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

The resulting type after applying the + operator.

Performs the + operation. Read more

Performs the += operation. Read more

Performs the conversion.

Performs the conversion.

The resulting type after applying the & operator.

Performs the & operation. Read more

Performs the &= operation. Read more

The resulting type after applying the | operator.

Performs the | operation. Read more

Performs the |= operation. Read more

The resulting type after applying the ^ operator.

Performs the ^ operation. Read more

Performs the ^= operation. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

The resulting type after dereferencing.

Dereferences the value.

Mutably dereferences the value.

Formats the value using the given formatter. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

Performs the /= operation. Read more

Performs the conversion.

Performs the conversion.

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

Performs the *= operation. Read more

The resulting type after applying the - operator.

Performs the unary - operation. Read more

The resulting type after applying the ! operator.

Performs the unary ! operation. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

The resulting type after applying the << operator.

Performs the << operation. Read more

Performs the <<= operation. Read more

The resulting type after applying the >> operator.

Performs the >> operation. Read more

Performs the >>= operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

Performs the -= operation. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.