MaybeOwnedMut

Enum MaybeOwnedMut 

Source
pub enum MaybeOwnedMut<'a, T>
where 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§

Source§

impl<T> MaybeOwnedMut<'_, T>

Source

pub fn is_owned(&self) -> bool

Returns true if the data is owned else false.

Source§

impl<T> MaybeOwnedMut<'_, T>
where T: Clone,

Source

pub fn into_owned(self) -> T

Return the contained data in it’s owned form.

If it’s borrowed this will clone it.

Source

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> Add<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
where L: Add<R, Output = OUT, Output = OUT> + Add<&'min R>, &'min L: Add<R, Output = OUT, Output = OUT> + Add<&'min R>, OUT: 'min,

Source§

type Output = OUT

The resulting type after applying the + operator.
Source§

fn add( self, rhs: MaybeOwnedMut<'min, R>, ) -> <MaybeOwnedMut<'min, L> as Add<MaybeOwnedMut<'min, R>>>::Output

Performs the + operation. Read more
Source§

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

Source§

fn add_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)

Performs the += operation. Read more
Source§

impl<T> AsMut<T> for MaybeOwnedMut<'_, T>

Source§

fn as_mut(&mut self) -> &mut T

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<T> AsRef<T> for MaybeOwnedMut<'_, T>

Source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'min, L, R, OUT> BitAnd<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
where L: BitAnd<R, Output = OUT, Output = OUT> + BitAnd<&'min R>, &'min L: BitAnd<R, Output = OUT, Output = OUT> + BitAnd<&'min R>, OUT: 'min,

Source§

type Output = OUT

The resulting type after applying the & operator.
Source§

fn bitand( self, rhs: MaybeOwnedMut<'min, R>, ) -> <MaybeOwnedMut<'min, L> as BitAnd<MaybeOwnedMut<'min, R>>>::Output

Performs the & operation. Read more
Source§

impl<'min, L, R> BitAndAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>

Source§

fn bitand_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)

Performs the &= operation. Read more
Source§

impl<'min, L, R, OUT> BitOr<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
where L: BitOr<R, Output = OUT, Output = OUT> + BitOr<&'min R>, &'min L: BitOr<R, Output = OUT, Output = OUT> + BitOr<&'min R>, OUT: 'min,

Source§

type Output = OUT

The resulting type after applying the | operator.
Source§

fn bitor( self, rhs: MaybeOwnedMut<'min, R>, ) -> <MaybeOwnedMut<'min, L> as BitOr<MaybeOwnedMut<'min, R>>>::Output

Performs the | operation. Read more
Source§

impl<'min, L, R> BitOrAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>

Source§

fn bitor_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)

Performs the |= operation. Read more
Source§

impl<'min, L, R, OUT> BitXor<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
where L: BitXor<R, Output = OUT, Output = OUT> + BitXor<&'min R>, &'min L: BitXor<R, Output = OUT, Output = OUT> + BitXor<&'min R>, OUT: 'min,

Source§

type Output = OUT

The resulting type after applying the ^ operator.
Source§

fn bitxor( self, rhs: MaybeOwnedMut<'min, R>, ) -> <MaybeOwnedMut<'min, L> as BitXor<MaybeOwnedMut<'min, R>>>::Output

Performs the ^ operation. Read more
Source§

impl<'min, L, R> BitXorAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>

Source§

fn bitxor_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)

Performs the ^= operation. Read more
Source§

impl<T> Borrow<T> for MaybeOwnedMut<'_, T>

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for MaybeOwnedMut<'_, T>

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<'a, T> Debug for MaybeOwnedMut<'a, T>
where T: Debug + 'a,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T> Default for MaybeOwnedMut<'_, T>
where T: Default,

Source§

fn default() -> MaybeOwnedMut<'_, T>

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

impl<T> Deref for MaybeOwnedMut<'_, T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &T

Dereferences the value.
Source§

impl<T> DerefMut for MaybeOwnedMut<'_, T>

Source§

fn deref_mut(&mut self) -> &mut T

Mutably dereferences the value.
Source§

impl<'a, T> Display for MaybeOwnedMut<'a, T>
where T: Display,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'min, L, R, OUT> Div<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
where L: Div<R, Output = OUT, Output = OUT> + Div<&'min R>, &'min L: Div<R, Output = OUT, Output = OUT> + Div<&'min R>, OUT: 'min,

Source§

type Output = OUT

The resulting type after applying the / operator.
Source§

fn div( self, rhs: MaybeOwnedMut<'min, R>, ) -> <MaybeOwnedMut<'min, L> as Div<MaybeOwnedMut<'min, R>>>::Output

Performs the / operation. Read more
Source§

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

Source§

fn div_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)

Performs the /= operation. Read more
Source§

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

Source§

fn from(v: &'a mut T) -> MaybeOwnedMut<'a, T>

Converts to this type from the input type.
Source§

impl<T> From<T> for MaybeOwnedMut<'_, T>

Source§

fn from(v: T) -> MaybeOwnedMut<'_, T>

Converts to this type from the input type.
Source§

impl<T> FromStr for MaybeOwnedMut<'_, T>
where T: FromStr,

Source§

type Err = <T as FromStr>::Err

The associated error which can be returned from parsing.
Source§

fn from_str( s: &str, ) -> Result<MaybeOwnedMut<'_, T>, <MaybeOwnedMut<'_, T> as FromStr>::Err>

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

impl<T> Hash for MaybeOwnedMut<'_, T>
where T: Hash,

Source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

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

impl<'min, L, R, OUT> Mul<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
where L: Mul<R, Output = OUT, Output = OUT> + Mul<&'min R>, &'min L: Mul<R, Output = OUT, Output = OUT> + Mul<&'min R>, OUT: 'min,

Source§

type Output = OUT

The resulting type after applying the * operator.
Source§

fn mul( self, rhs: MaybeOwnedMut<'min, R>, ) -> <MaybeOwnedMut<'min, L> as Mul<MaybeOwnedMut<'min, R>>>::Output

Performs the * operation. Read more
Source§

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

Source§

fn mul_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)

Performs the *= operation. Read more
Source§

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

Source§

type Output = OUT

The resulting type after applying the - operator.
Source§

fn neg(self) -> <MaybeOwnedMut<'l, V> as Neg>::Output

Performs the unary - operation. Read more
Source§

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

Source§

type Output = <V as Not>::Output

The resulting type after applying the ! operator.
Source§

fn not(self) -> <MaybeOwnedMut<'l, V> as Not>::Output

Performs the unary ! operation. Read more
Source§

impl<T> Ord for MaybeOwnedMut<'_, T>
where T: Ord,

Source§

fn cmp(&self, other: &MaybeOwnedMut<'_, T>) -> Ordering

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

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<'b, A, B> PartialEq<MaybeOwnedMut<'b, B>> for MaybeOwnedMut<'_, A>
where A: PartialEq<B>,

Source§

fn eq(&self, other: &MaybeOwnedMut<'b, B>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> PartialOrd for MaybeOwnedMut<'_, T>
where T: PartialOrd,

Source§

fn partial_cmp(&self, other: &MaybeOwnedMut<'_, T>) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'min, L, R, OUT> Shl<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
where L: Shl<R, Output = OUT, Output = OUT> + Shl<&'min R>, &'min L: Shl<R, Output = OUT, Output = OUT> + Shl<&'min R>, OUT: 'min,

Source§

type Output = OUT

The resulting type after applying the << operator.
Source§

fn shl( self, rhs: MaybeOwnedMut<'min, R>, ) -> <MaybeOwnedMut<'min, L> as Shl<MaybeOwnedMut<'min, R>>>::Output

Performs the << operation. Read more
Source§

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

Source§

fn shl_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)

Performs the <<= operation. Read more
Source§

impl<'min, L, R, OUT> Shr<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
where L: Shr<R, Output = OUT, Output = OUT> + Shr<&'min R>, &'min L: Shr<R, Output = OUT, Output = OUT> + Shr<&'min R>, OUT: 'min,

Source§

type Output = OUT

The resulting type after applying the >> operator.
Source§

fn shr( self, rhs: MaybeOwnedMut<'min, R>, ) -> <MaybeOwnedMut<'min, L> as Shr<MaybeOwnedMut<'min, R>>>::Output

Performs the >> operation. Read more
Source§

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

Source§

fn shr_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)

Performs the >>= operation. Read more
Source§

impl<'min, L, R, OUT> Sub<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
where L: Sub<R, Output = OUT, Output = OUT> + Sub<&'min R>, &'min L: Sub<R, Output = OUT, Output = OUT> + Sub<&'min R>, OUT: 'min,

Source§

type Output = OUT

The resulting type after applying the - operator.
Source§

fn sub( self, rhs: MaybeOwnedMut<'min, R>, ) -> <MaybeOwnedMut<'min, L> as Sub<MaybeOwnedMut<'min, R>>>::Output

Performs the - operation. Read more
Source§

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

Source§

fn sub_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)

Performs the -= operation. Read more
Source§

impl<'a, T> Eq for MaybeOwnedMut<'a, T>
where T: Eq,

Auto Trait Implementations§

§

impl<'a, T> Freeze for MaybeOwnedMut<'a, T>
where T: Freeze,

§

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,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<T> From<!> for T

§

fn from(t: !) -> T

Converts to this type from the input type.
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromWorld for T
where T: Default,

Source§

fn from_world(_world: &World) -> T

Creates Self using data from the given World.
§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> RawDefault for T
where T: Default,

Source§

unsafe fn raw_default(dst: *mut c_void)

Write the default value of the type to the pointer. Read more
Source§

fn raw_default_cb() -> Unsafe<&'static (dyn Fn(*mut c_void) + Sync + Send)>

Get a callback suitable for [SchemaData].
Source§

impl<T> RawDrop for T

Source§

unsafe fn raw_drop(ptr: *mut c_void)

Write the default value of the type to the pointer. Read more
Source§

fn raw_drop_cb() -> Unsafe<&'static (dyn Fn(*mut c_void) + Sync + Send)>

Get a callback suitable for [SchemaData].
Source§

impl<T> RawEq for T
where T: Eq,

Source§

unsafe fn raw_eq(a: *const c_void, b: *const c_void) -> bool

Get the hash of the type. Read more
Source§

fn raw_eq_cb() -> Unsafe<&'static (dyn Fn(*const c_void, *const c_void) -> bool + Sync + Send)>

Get a callback suitable for [SchemaData].
Source§

impl<T> RawHash for T
where T: Hash,

Source§

unsafe fn raw_hash(ptr: *const c_void) -> u64

Get the hash of the type. Read more
Source§

fn raw_hash_cb() -> Unsafe<&'static (dyn Fn(*const c_void) -> u64 + Sync + Send)>

Get a callback suitable for [SchemaData].
§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<R> Rng for R
where R: RngCore + ?Sized,

Source§

fn random<T>(&mut self) -> T

Return a random value via the StandardUniform distribution. Read more
Source§

fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>

Return an iterator over random variates Read more
Source§

fn random_range<T, R>(&mut self, range: R) -> T
where T: SampleUniform, R: SampleRange<T>,

Generate a random value in the given range. Read more
Source§

fn random_bool(&mut self, p: f64) -> bool

Return a bool with a probability p of being true. Read more
Source§

fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool

Return a bool with a probability of numerator/denominator of being true. Read more
Source§

fn sample<T, D>(&mut self, distr: D) -> T
where D: Distribution<T>,

Sample a new value, using the given distribution. Read more
Source§

fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T>
where D: Distribution<T>, Self: Sized,

Create an iterator that generates values using the given distribution. Read more
Source§

fn fill<T>(&mut self, dest: &mut T)
where T: Fill + ?Sized,

Fill any type implementing Fill with random data Read more
Source§

fn gen<T>(&mut self) -> T

👎Deprecated since 0.9.0: Renamed to random to avoid conflict with the new gen keyword in Rust 2024.
Alias for Rng::random.
Source§

fn gen_range<T, R>(&mut self, range: R) -> T
where T: SampleUniform, R: SampleRange<T>,

👎Deprecated since 0.9.0: Renamed to random_range
Source§

fn gen_bool(&mut self, p: f64) -> bool

👎Deprecated since 0.9.0: Renamed to random_bool
Alias for Rng::random_bool.
Source§

fn gen_ratio(&mut self, numerator: u32, denominator: u32) -> bool

👎Deprecated since 0.9.0: Renamed to random_ratio
Source§

impl<T> RngCore for T
where T: DerefMut, <T as Deref>::Target: RngCore,

Source§

fn next_u32(&mut self) -> u32

Return the next random u32. Read more
Source§

fn next_u64(&mut self) -> u64

Return the next random u64. Read more
Source§

fn fill_bytes(&mut self, dst: &mut [u8])

Fill dest with random data. Read more
§

impl<T> ToString for T
where T: Display + ?Sized,

§

fn to_string(&self) -> String

Converts the given value to a String. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<R> TryRngCore for R
where R: RngCore + ?Sized,

Source§

type Error = Infallible

The type returned in the event of a RNG error.
Source§

fn try_next_u32(&mut self) -> Result<u32, <R as TryRngCore>::Error>

Return the next random u32.
Source§

fn try_next_u64(&mut self) -> Result<u64, <R as TryRngCore>::Error>

Return the next random u64.
Source§

fn try_fill_bytes( &mut self, dst: &mut [u8], ) -> Result<(), <R as TryRngCore>::Error>

Fill dest entirely with random data.
Source§

fn unwrap_err(self) -> UnwrapErr<Self>
where Self: Sized,

Wrap RNG with the UnwrapErr wrapper.
Source§

fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>

Wrap RNG with the UnwrapMut wrapper.
Source§

fn read_adapter(&mut self) -> RngReadAdapter<'_, Self>
where Self: Sized,

Convert an RngCore to a RngReadAdapter.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> CryptoRng for T
where T: DerefMut, <T as Deref>::Target: CryptoRng,

Source§

impl<R> TryCryptoRng for R
where R: CryptoRng + ?Sized,