Expand description
A Cow<'a, [u8]>
wrapper that supports serializing efficiently in Serde.
Tuple Fields
0: Cow<'a, [u8]>
Implementations
sourceimpl<'a> CowBytes<'a>
impl<'a> CowBytes<'a>
Methods from Deref<Target = Cow<'a, [u8]>>
sourcepub fn is_borrowed(&self) -> bool
🔬 This is a nightly-only experimental API. (cow_is_borrowed
)
pub fn is_borrowed(&self) -> bool
cow_is_borrowed
)Returns true if the data is borrowed, i.e. if to_mut
would require additional work.
Examples
#![feature(cow_is_borrowed)]
use std::borrow::Cow;
let cow = Cow::Borrowed("moo");
assert!(cow.is_borrowed());
let bull: Cow<'_, str> = Cow::Owned("...moo?".to_string());
assert!(!bull.is_borrowed());
sourcepub fn is_owned(&self) -> bool
🔬 This is a nightly-only experimental API. (cow_is_borrowed
)
pub fn is_owned(&self) -> bool
cow_is_borrowed
)Returns true if the data is owned, i.e. if to_mut
would be a no-op.
Examples
#![feature(cow_is_borrowed)]
use std::borrow::Cow;
let cow: Cow<'_, str> = Cow::Owned("moo".to_string());
assert!(cow.is_owned());
let bull = Cow::Borrowed("...moo?");
assert!(!bull.is_owned());
1.0.0 · sourcepub fn to_mut(&mut self) -> &mut <B as ToOwned>::Owned
pub fn to_mut(&mut self) -> &mut <B as ToOwned>::Owned
Acquires a mutable reference to the owned form of the data.
Clones the data if it is not already owned.
Examples
use std::borrow::Cow;
let mut cow = Cow::Borrowed("foo");
cow.to_mut().make_ascii_uppercase();
assert_eq!(
cow,
Cow::Owned(String::from("FOO")) as Cow<str>
);
Trait Implementations
sourceimpl<'de: 'a, 'a> Deserialize<'de> for CowBytes<'a>
impl<'de: 'a, 'a> Deserialize<'de> for CowBytes<'a>
sourcefn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl<'a> Ord for CowBytes<'a>
impl<'a> Ord for CowBytes<'a>
sourceimpl<'a, 'b, const SIZE: usize> PartialOrd<&'b [u8; SIZE]> for CowBytes<'a>
impl<'a, 'b, const SIZE: usize> PartialOrd<&'b [u8; SIZE]> for CowBytes<'a>
sourcefn partial_cmp(&self, other: &&'b [u8; SIZE]) -> Option<Ordering>
fn partial_cmp(&self, other: &&'b [u8; SIZE]) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl<'b, 'a> PartialOrd<&'b [u8]> for CowBytes<'a>
impl<'b, 'a> PartialOrd<&'b [u8]> for CowBytes<'a>
sourcefn partial_cmp(&self, other: &&'b [u8]) -> Option<Ordering>
fn partial_cmp(&self, other: &&'b [u8]) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl<'a> PartialOrd<[u8]> for CowBytes<'a>
impl<'a> PartialOrd<[u8]> for CowBytes<'a>
sourcefn partial_cmp(&self, other: &[u8]) -> Option<Ordering>
fn partial_cmp(&self, other: &[u8]) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl<'a> PartialOrd<CowBytes<'a>> for CowBytes<'a>
impl<'a> PartialOrd<CowBytes<'a>> for CowBytes<'a>
sourcefn partial_cmp(&self, other: &CowBytes<'a>) -> Option<Ordering>
fn partial_cmp(&self, other: &CowBytes<'a>) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl<'a> Eq for CowBytes<'a>
impl<'a> StructuralEq for CowBytes<'a>
impl<'a> StructuralPartialEq for CowBytes<'a>
Auto Trait Implementations
impl<'a> RefUnwindSafe for CowBytes<'a>
impl<'a> Send for CowBytes<'a>
impl<'a> Sync for CowBytes<'a>
impl<'a> Unpin for CowBytes<'a>
impl<'a> UnwindSafe for CowBytes<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more