#[repr(transparent)]pub struct Owned<B>(pub <B as ToOwned>::Owned)
where
B: ?Sized + ToOwned;
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>
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
.
impl<B, U> AsRef<U> for Owned<B>
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> GenericCow for Owned<B>
impl<B> GenericCow for Owned<B>
Source§impl<B> Ord for Owned<B>
impl<B> Ord for Owned<B>
Source§impl<B, C> PartialOrd<Owned<C>> for Owned<B>
impl<B, C> PartialOrd<Owned<C>> for Owned<B>
impl<B> Eq for Owned<B>
Auto Trait Implementations§
impl<B> Freeze for Owned<B>
impl<B> RefUnwindSafe for Owned<B>
impl<B> Send for Owned<B>
impl<B> Sync for Owned<B>
impl<B> Unpin for Owned<B>
impl<B> UnwindSafe for Owned<B>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more