[−][src]Trait into_owned::IntoOwned
A trait for associating a type with its owned variant.
Examples
Implementing the IntoOwned
trait for an owned type is straighitforward.
Maybe a derive macro is supplied in future.
Since there are blanket implementations for &T
and &mut T
where
T: IntoOwned<Owned = T> + Clone
,
manually implementing IntoOwned
for the owned type is sufficient in most cases.
use into_owned::IntoOwned; #[derive(Clone)] struct A(); impl IntoOwned for A { type Owned = Self; const IS_OWNED: bool = true; fn into_owned(self) -> Self::Owned { self } } // this function can be called with an owned or borrowed value fn is_owned<T>(t: T) -> bool where T: IntoOwned { T::IS_OWNED } assert!(is_owned(A())); assert!(!is_owned(&A())); assert!(!is_owned(&mut A()));
Associated Types
type Owned
The owned type associated with Self
.
Associated Constants
Loading content...Required methods
fn into_owned(self) -> Self::Owned
Converts self
into an owned value.
If self
is an owned value (i.e. Self
and Self::Owned
are the same),
usually it just returns self
.
If self
is a borrowed value, usually it returns an owned value by cloning.
Implementations on Foreign Types
impl<'_, T> IntoOwned for &'_ T where
T: IntoOwned<Owned = T> + Clone,
[src]
T: IntoOwned<Owned = T> + Clone,
impl<'_, T> IntoOwned for &'_ mut T where
T: IntoOwned<Owned = T> + Clone,
[src]
T: IntoOwned<Owned = T> + Clone,