pub struct Owned<B>(pub <B as ToOwned>::Owned)
where
B: ToOwned + ?Sized;
Expand description
Wrapper akin to Cow::Owned
but known to be owned at compile-time
The wrapper takes a type argument B
and a value of type
<B as ToOwned>::Owned
.
It supports dereference (with B
being the target),
implements Borrow<B>
, and
GenericCow<Borrowed = B>
.
Example
use deref_owned::{GenericCow, Owned};
use std::borrow::Cow;
fn generic_fn(arg: impl GenericCow<Borrowed = str>) { /* ... */ }
generic_fn(Owned("Hello".to_string()));
generic_fn(Cow::Owned("Hello".to_string()));
generic_fn(Cow::Borrowed("Hello"));
generic_fn("Hello");
Tuple Fields§
§0: <B as ToOwned>::Owned
Trait Implementations§
source§impl<B, U> AsRef<U> for Owned<B>where
B: ToOwned + ?Sized,
<B as ToOwned>::Owned: AsRef<U>,
U: ?Sized,
impl<B, U> AsRef<U> for Owned<B>where B: ToOwned + ?Sized, <B as ToOwned>::Owned: AsRef<U>, U: ?Sized,
AsRef
is only implemented when the inner type implements
AsRef
. This is consistent with the blanket implementation of AsRef
for
shared references but not consistent with Cow
’s
implementation of AsRef
.
source§impl<B> Display for Owned<B>where
B: Display + ToOwned + ?Sized,
<B as ToOwned>::Owned: Display,
impl<B> Display for Owned<B>where B: Display + ToOwned + ?Sized, <B as ToOwned>::Owned: Display,
source§impl<B> Ord for Owned<B>where
B: ToOwned + ?Sized,
<B as ToOwned>::Owned: Ord,
impl<B> Ord for Owned<B>where B: ToOwned + ?Sized, <B as ToOwned>::Owned: Ord,
source§impl<B, C> PartialEq<Owned<C>> for Owned<B>where
B: ToOwned + ?Sized,
C: ToOwned + ?Sized,
<B as ToOwned>::Owned: PartialEq<<C as ToOwned>::Owned>,
impl<B, C> PartialEq<Owned<C>> for Owned<B>where B: ToOwned + ?Sized, C: ToOwned + ?Sized, <B as ToOwned>::Owned: PartialEq<<C as ToOwned>::Owned>,
source§impl<B, C> PartialOrd<Owned<C>> for Owned<B>where
B: ToOwned + ?Sized,
C: ToOwned + ?Sized,
<B as ToOwned>::Owned: PartialOrd<<C as ToOwned>::Owned>,
impl<B, C> PartialOrd<Owned<C>> for Owned<B>where B: ToOwned + ?Sized, C: ToOwned + ?Sized, <B as ToOwned>::Owned: PartialOrd<<C as ToOwned>::Owned>,
source§fn le(&self, other: &Owned<C>) -> bool
fn le(&self, other: &Owned<C>) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read more