Enum bones_asset::bones_utils::prelude::MaybeOwnedMut
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§
Implementations§
§impl<T> MaybeOwnedMut<'_, T>
impl<T> MaybeOwnedMut<'_, T>
§impl<T> MaybeOwnedMut<'_, T>where
T: Clone,
impl<T> MaybeOwnedMut<'_, T>where
T: Clone,
pub 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.
pub 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§
§impl<'min, L, R, OUT> Add<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
impl<'min, L, R, OUT> Add<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
§fn add(
self,
rhs: MaybeOwnedMut<'min, R>,
) -> <MaybeOwnedMut<'min, L> as Add<MaybeOwnedMut<'min, R>>>::Output
fn add( self, rhs: MaybeOwnedMut<'min, R>, ) -> <MaybeOwnedMut<'min, L> as Add<MaybeOwnedMut<'min, R>>>::Output
+
operation. Read more§impl<'min, L, R> AddAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
impl<'min, L, R> AddAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
§fn add_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
fn add_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
+=
operation. Read more§impl<T> AsMut<T> for MaybeOwnedMut<'_, T>
impl<T> AsMut<T> for MaybeOwnedMut<'_, T>
§impl<T> AsRef<T> for MaybeOwnedMut<'_, T>
impl<T> AsRef<T> for MaybeOwnedMut<'_, T>
§impl<'min, L, R, OUT> BitAnd<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
impl<'min, L, R, OUT> BitAnd<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
§fn bitand(
self,
rhs: MaybeOwnedMut<'min, R>,
) -> <MaybeOwnedMut<'min, L> as BitAnd<MaybeOwnedMut<'min, R>>>::Output
fn bitand( self, rhs: MaybeOwnedMut<'min, R>, ) -> <MaybeOwnedMut<'min, L> as BitAnd<MaybeOwnedMut<'min, R>>>::Output
&
operation. Read more§impl<'min, L, R> BitAndAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
impl<'min, L, R> BitAndAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
§fn bitand_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
fn bitand_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
&=
operation. Read more§impl<'min, L, R, OUT> BitOr<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
impl<'min, L, R, OUT> BitOr<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
§fn bitor(
self,
rhs: MaybeOwnedMut<'min, R>,
) -> <MaybeOwnedMut<'min, L> as BitOr<MaybeOwnedMut<'min, R>>>::Output
fn bitor( self, rhs: MaybeOwnedMut<'min, R>, ) -> <MaybeOwnedMut<'min, L> as BitOr<MaybeOwnedMut<'min, R>>>::Output
|
operation. Read more§impl<'min, L, R> BitOrAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
impl<'min, L, R> BitOrAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
§fn bitor_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
fn bitor_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
|=
operation. Read more§impl<'min, L, R, OUT> BitXor<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
impl<'min, L, R, OUT> BitXor<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
§fn bitxor(
self,
rhs: MaybeOwnedMut<'min, R>,
) -> <MaybeOwnedMut<'min, L> as BitXor<MaybeOwnedMut<'min, R>>>::Output
fn bitxor( self, rhs: MaybeOwnedMut<'min, R>, ) -> <MaybeOwnedMut<'min, L> as BitXor<MaybeOwnedMut<'min, R>>>::Output
^
operation. Read more§impl<'min, L, R> BitXorAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
impl<'min, L, R> BitXorAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
§fn bitxor_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
fn bitxor_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
^=
operation. Read more§impl<T> Borrow<T> for MaybeOwnedMut<'_, T>
impl<T> Borrow<T> for MaybeOwnedMut<'_, T>
§impl<T> BorrowMut<T> for MaybeOwnedMut<'_, T>
impl<T> BorrowMut<T> for MaybeOwnedMut<'_, T>
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<'a, T> Debug for MaybeOwnedMut<'a, T>where
T: Debug + 'a,
impl<'a, T> Debug for MaybeOwnedMut<'a, T>where
T: Debug + 'a,
§impl<T> Default for MaybeOwnedMut<'_, T>where
T: Default,
impl<T> Default for MaybeOwnedMut<'_, T>where
T: Default,
§fn default() -> MaybeOwnedMut<'_, T>
fn default() -> MaybeOwnedMut<'_, T>
§impl<T> Deref for MaybeOwnedMut<'_, T>
impl<T> Deref for MaybeOwnedMut<'_, T>
§impl<T> DerefMut for MaybeOwnedMut<'_, T>
impl<T> DerefMut for MaybeOwnedMut<'_, T>
§impl<'a, T> Display for MaybeOwnedMut<'a, T>where
T: Display,
impl<'a, T> Display for MaybeOwnedMut<'a, T>where
T: Display,
§impl<'min, L, R, OUT> Div<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
impl<'min, L, R, OUT> Div<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
§fn div(
self,
rhs: MaybeOwnedMut<'min, R>,
) -> <MaybeOwnedMut<'min, L> as Div<MaybeOwnedMut<'min, R>>>::Output
fn div( self, rhs: MaybeOwnedMut<'min, R>, ) -> <MaybeOwnedMut<'min, L> as Div<MaybeOwnedMut<'min, R>>>::Output
/
operation. Read more§impl<'min, L, R> DivAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
impl<'min, L, R> DivAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
§fn div_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
fn div_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
/=
operation. Read more§impl<'a, T> From<&'a mut T> for MaybeOwnedMut<'a, T>
impl<'a, T> From<&'a mut T> for MaybeOwnedMut<'a, T>
§fn from(v: &'a mut T) -> MaybeOwnedMut<'a, T>
fn from(v: &'a mut T) -> MaybeOwnedMut<'a, T>
§impl<T> From<T> for MaybeOwnedMut<'_, T>
impl<T> From<T> for MaybeOwnedMut<'_, T>
§fn from(v: T) -> MaybeOwnedMut<'_, T>
fn from(v: T) -> MaybeOwnedMut<'_, T>
§impl<T> FromStr for MaybeOwnedMut<'_, T>where
T: FromStr,
impl<T> FromStr for MaybeOwnedMut<'_, T>where
T: FromStr,
§impl<T> Hash for MaybeOwnedMut<'_, T>where
T: Hash,
impl<T> Hash for MaybeOwnedMut<'_, T>where
T: Hash,
§impl<'min, L, R, OUT> Mul<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
impl<'min, L, R, OUT> Mul<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
§fn mul(
self,
rhs: MaybeOwnedMut<'min, R>,
) -> <MaybeOwnedMut<'min, L> as Mul<MaybeOwnedMut<'min, R>>>::Output
fn mul( self, rhs: MaybeOwnedMut<'min, R>, ) -> <MaybeOwnedMut<'min, L> as Mul<MaybeOwnedMut<'min, R>>>::Output
*
operation. Read more§impl<'min, L, R> MulAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
impl<'min, L, R> MulAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
§fn mul_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
fn mul_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
*=
operation. Read more§impl<'l, V, OUT> Neg for MaybeOwnedMut<'l, V>
impl<'l, V, OUT> Neg for MaybeOwnedMut<'l, V>
§impl<'l, V, OUT> Not for MaybeOwnedMut<'l, V>
impl<'l, V, OUT> Not for MaybeOwnedMut<'l, V>
§impl<T> Ord for MaybeOwnedMut<'_, T>where
T: Ord,
impl<T> Ord for MaybeOwnedMut<'_, T>where
T: Ord,
§fn cmp(&self, other: &MaybeOwnedMut<'_, T>) -> Ordering
fn cmp(&self, other: &MaybeOwnedMut<'_, T>) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
§impl<'b, A, B> PartialEq<MaybeOwnedMut<'b, B>> for MaybeOwnedMut<'_, A>where
A: PartialEq<B>,
impl<'b, A, B> PartialEq<MaybeOwnedMut<'b, B>> for MaybeOwnedMut<'_, A>where
A: PartialEq<B>,
§fn eq(&self, other: &MaybeOwnedMut<'b, B>) -> bool
fn eq(&self, other: &MaybeOwnedMut<'b, B>) -> bool
self
and other
values to be equal, and is used
by ==
.§impl<T> PartialOrd for MaybeOwnedMut<'_, T>where
T: PartialOrd,
impl<T> PartialOrd for MaybeOwnedMut<'_, T>where
T: PartialOrd,
§fn partial_cmp(&self, other: &MaybeOwnedMut<'_, T>) -> Option<Ordering>
fn partial_cmp(&self, other: &MaybeOwnedMut<'_, T>) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more§impl<'min, L, R, OUT> Shl<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
impl<'min, L, R, OUT> Shl<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
§fn shl(
self,
rhs: MaybeOwnedMut<'min, R>,
) -> <MaybeOwnedMut<'min, L> as Shl<MaybeOwnedMut<'min, R>>>::Output
fn shl( self, rhs: MaybeOwnedMut<'min, R>, ) -> <MaybeOwnedMut<'min, L> as Shl<MaybeOwnedMut<'min, R>>>::Output
<<
operation. Read more§impl<'min, L, R> ShlAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
impl<'min, L, R> ShlAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
§fn shl_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
fn shl_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
<<=
operation. Read more§impl<'min, L, R, OUT> Shr<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
impl<'min, L, R, OUT> Shr<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
§fn shr(
self,
rhs: MaybeOwnedMut<'min, R>,
) -> <MaybeOwnedMut<'min, L> as Shr<MaybeOwnedMut<'min, R>>>::Output
fn shr( self, rhs: MaybeOwnedMut<'min, R>, ) -> <MaybeOwnedMut<'min, L> as Shr<MaybeOwnedMut<'min, R>>>::Output
>>
operation. Read more§impl<'min, L, R> ShrAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
impl<'min, L, R> ShrAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
§fn shr_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
fn shr_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
>>=
operation. Read more§impl<'min, L, R, OUT> Sub<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
impl<'min, L, R, OUT> Sub<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
§fn sub(
self,
rhs: MaybeOwnedMut<'min, R>,
) -> <MaybeOwnedMut<'min, L> as Sub<MaybeOwnedMut<'min, R>>>::Output
fn sub( self, rhs: MaybeOwnedMut<'min, R>, ) -> <MaybeOwnedMut<'min, L> as Sub<MaybeOwnedMut<'min, R>>>::Output
-
operation. Read more§impl<'min, L, R> SubAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
impl<'min, L, R> SubAssign<MaybeOwnedMut<'min, R>> for MaybeOwnedMut<'min, L>
§fn sub_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
fn sub_assign(&mut self, rhs: MaybeOwnedMut<'min, R>)
-=
operation. Read moreimpl<'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§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.