AsCopy

Struct AsCopy 

Source
#[repr(transparent)]
pub struct AsCopy<T>(pub T) where T: Copy;
Expand description

Transparent wrapper for Copyable types to support all traits (by copying).

#[derive(Clone, Copy)]
struct NotIntoOwned;

fn requires_to_owned<O: IntoOwned>(o: O) {
  // do stuff
}

// `AsCopy<NotIntoOwned>` implements `IntoOwned` through `Copy`
requires_to_owned(AsCopy(NotIntoOwned));

All trait impls work on the inner value as if there is no layer in between (e.g. Display does not add a AsCopy to the output).

Tuple Fields§

§0: T

Trait Implementations§

Source§

impl<T> Borrow<T> for AsCopy<T>
where T: Copy,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for AsCopy<T>
where T: Copy,

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> Debug for AsCopy<T>
where T: Copy + Debug,

Source§

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

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

impl<T> Default for AsCopy<T>
where T: Copy + Default,

Source§

fn default() -> AsCopy<T>

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

impl<T> Deref for AsCopy<T>
where T: Copy,

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &<AsCopy<T> as Deref>::Target

Dereferences the value.
Source§

impl<T> DerefMut for AsCopy<T>
where T: Copy,

Source§

fn deref_mut(&mut self) -> &mut <AsCopy<T> as Deref>::Target

Mutably dereferences the value.
Source§

impl<T> Display for AsCopy<T>
where T: Copy + Display,

Source§

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

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

impl<T> From<T> for AsCopy<T>
where T: Copy,

Source§

fn from(value: T) -> AsCopy<T>

Converts to this type from the input type.
Source§

impl<T> Hash for AsCopy<T>
where T: Copy + Hash,

Source§

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

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> IntoOwned for AsCopy<T>
where T: Copy,

Source§

type Owned = AsCopy<T>

The type after obtaining ownership, should be the same as before but with static lifetime.
Source§

fn into_owned(self) -> <AsCopy<T> as IntoOwned>::Owned

Copy the structure and clone the original values if it’s not owned. Read more
Source§

impl<T> Ord for AsCopy<T>
where T: Copy + Ord,

Source§

fn cmp(&self, other: &AsCopy<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 AsCopy<T>
where T: Copy + PartialEq,

Source§

fn eq(&self, other: &AsCopy<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 AsCopy<T>
where T: Copy + PartialOrd,

Source§

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

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

fn lt(&self, other: &AsCopy<T>) -> bool

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

fn le(&self, other: &AsCopy<T>) -> bool

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

fn gt(&self, other: &AsCopy<T>) -> bool

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

fn ge(&self, other: &AsCopy<T>) -> bool

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

impl<T> ToBorrowed<'_> for AsCopy<T>
where T: Copy,

Source§

fn to_borrowed(&self) -> AsCopy<T>

Copy the structure and reference the original values. Read more
Source§

impl<T> ToOwned for AsCopy<T>
where T: Copy,

Source§

type Owned = AsCopy<T>

The type after obtaining ownership, should be the same as before but with static lifetime.
Source§

fn to_owned(&self) -> <AsCopy<T> as ToOwned>::Owned

Copy the structure and clone the original values. Read more
Source§

impl<T> Eq for AsCopy<T>
where T: Copy + Eq,

Auto Trait Implementations§

§

impl<T> Freeze for AsCopy<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for AsCopy<T>
where T: RefUnwindSafe,

§

impl<T> Send for AsCopy<T>
where T: Send,

§

impl<T> Sync for AsCopy<T>
where T: Sync,

§

impl<T> Unpin for AsCopy<T>
where T: Unpin,

§

impl<T> UnwindSafe for AsCopy<T>
where T: 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> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
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<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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.