Struct ownable::AsCopy

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

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

// Simple struct which uses `Ipv4Addr` with the help of `AsCopy`.
// As an alternative it's possible to impl the ownable traits by hand (for own types, not `Ipv4Addr`).
#[derive(IntoOwned, ToBorrowed, ToOwned)]
struct MyMap<'a>(HashMap<AsCopy<Ipv4Addr>, Cow<'a, str>>);

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: Copy> Borrow<T> for AsCopy<T>

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

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

source§

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

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

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

source§

fn default() -> Self

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

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

§

type Target = T

The resulting type after dereferencing.
source§

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

Dereferences the value.
source§

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

source§

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

Mutably dereferences the value.
source§

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

source§

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

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

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

source§

fn from(value: T) -> Self

Converts to this type from the input type.
source§

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

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

§

type Owned = AsCopy<T>

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

fn into_owned(self) -> Self::Owned

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

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

source§

fn cmp(&self, other: &Self) -> 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 + PartialOrd,

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

impl<T: Copy + PartialEq> PartialEq for AsCopy<T>

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: Copy + PartialOrd> PartialOrd for AsCopy<T>

source§

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

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

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

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

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

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

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

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

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

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

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

source§

fn to_borrowed(&self) -> Self

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

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

§

type Owned = AsCopy<T>

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

fn to_owned(&self) -> Self::Owned

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

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

Auto Trait Implementations§

§

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<T> ToString for T
where T: Display + ?Sized,

source§

default 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>,

§

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>,

§

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.