pub struct CowBytes<'a>(pub Cow<'a, [u8]>);Expand description
A Cow<'a, [u8]> wrapper that supports serializing efficiently in Serde.
Tuple Fields§
§0: Cow<'a, [u8]>Implementations§
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§
Source§impl<'de: 'a, 'a> Deserialize<'de> for CowBytes<'a>
impl<'de: 'a, 'a> Deserialize<'de> for CowBytes<'a>
Source§fn 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
Source§impl<'a> Ord for CowBytes<'a>
impl<'a> Ord for CowBytes<'a>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<'b, 'a> PartialOrd<&'b [u8]> for CowBytes<'a>
impl<'b, 'a> PartialOrd<&'b [u8]> for CowBytes<'a>
Source§impl<'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>
Source§impl<'a> PartialOrd<[u8]> for CowBytes<'a>
impl<'a> PartialOrd<[u8]> for CowBytes<'a>
Source§impl<'a> PartialOrd for CowBytes<'a>
impl<'a> PartialOrd for CowBytes<'a>
impl<'a> Eq for CowBytes<'a>
impl<'a> StructuralPartialEq for CowBytes<'a>
Auto Trait Implementations§
impl<'a> Freeze for CowBytes<'a>
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§
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