Keep

Struct Keep 

Source
pub struct Keep<T>(pub T::Owning)
where
    T: ToOwning;
Expand description

An Idempotent implementation which wraps a type that is already Owning.

Keep has an additional function outside of its use with Idempotent, which is that it implements Clone. Recall that all types which implement Clone have a blanket implementation of IntoOwning which is just the identity function. Contrapositively, therefore, any type with a non-trivial IntoOwning implementation cannot implement Clone. Usually, the conversion target of a struct’s or enum’s IntoOwning implementation is the same struct or enum with different generic parameters. You might wish to be able to clone such an object after it has already been converted into its owning form, but this is not possible because it breaks Rust’s rules about conflicting trait implementations. If you already know you have a type that IntoOwning (and therefore implements its supertrait ToOwning), then you can work around this by calling .to_owning() instead of .clone() and this will do the same thing. However, if you need to pass the object to something whose generic bounds require a Clone implementation, wrapping it with Keep can be a convenient solution.

Tuple Fields§

§0: T::Owning

Trait Implementations§

Source§

impl<T> Clone for Keep<T>
where T: ToOwning, T::Owning: ToOwning<Owning = T::Owning>,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for Keep<T>
where T: ToOwning + Debug, T::Owning: Debug,

Source§

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

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

impl<T> Default for Keep<T>
where T: ToOwning + Default, T::Owning: Default,

Source§

fn default() -> Keep<T>

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

impl<T> Deref for Keep<T>
where T: ToOwning,

Source§

type Target = <T as ToOwning>::Owning

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T> DerefMut for Keep<T>
where T: ToOwning,

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<T> Hash for Keep<T>
where T: ToOwning + Hash, T::Owning: Hash,

Source§

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

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

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<T> Idempotent<T> for Keep<T>
where T: IntoOwning, T::Owning: ToOwning<Owning = T::Owning>,

Source§

fn to_ref(&self) -> IdemRef<'_, T>

Get a reference to either a T or a T::Owning.
Source§

fn to_mut(&mut self) -> IdemMut<'_, T>

Get a mutable reference to either a T or a T::Owning.
Source§

fn into_kept(self) -> T::Owning

Converts self into a T::Owning; equivalent to into_owning().0.
Source§

impl<T> Ord for Keep<T>
where T: ToOwning + Ord, T::Owning: Ord,

Source§

fn cmp(&self, other: &Keep<T>) -> Ordering

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

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

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

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

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

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

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

impl<T> PartialEq for Keep<T>

Source§

fn eq(&self, other: &Keep<T>) -> bool

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

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 Keep<T>

Source§

fn partial_cmp(&self, other: &Keep<T>) -> Option<Ordering>

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

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

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

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 · Source§

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

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

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<T> Eq for Keep<T>
where T: ToOwning + Eq, T::Owning: Eq,

Source§

impl<T> StructuralPartialEq for Keep<T>
where T: ToOwning,

Auto Trait Implementations§

§

impl<T> Freeze for Keep<T>
where <T as ToOwning>::Owning: Freeze,

§

impl<T> RefUnwindSafe for Keep<T>
where <T as ToOwning>::Owning: RefUnwindSafe,

§

impl<T> Send for Keep<T>
where <T as ToOwning>::Owning: Send,

§

impl<T> Sync for Keep<T>
where <T as ToOwning>::Owning: Sync,

§

impl<T> Unpin for Keep<T>
where <T as ToOwning>::Owning: Unpin,

§

impl<T> UnwindSafe for Keep<T>
where <T as ToOwning>::Owning: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

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<B> IntoOwning for B
where B: Clone,

Source§

fn into_owning(self) -> <B as ToOwning>::Owning

Converts an object which owns its contents into one which borrows them.
Source§

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

Source§

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<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<B> ToOwning for B
where B: ToOwned + ?Sized,

Source§

type Owning = <B as ToOwned>::Owned

The resulting type after obtaining ownership of self’s contents.
Source§

fn to_owning(&self) -> <B as ToOwning>::Owning

Creates an object which owns its contents from one which borrows them.
Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.