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§
§impl<'de, 'a> Deserialize<'de> for CowBytes<'a>where
'de: 'a,
impl<'de, 'a> Deserialize<'de> for CowBytes<'a>where 'de: 'a,
§fn deserialize<D>(
deserializer: D
) -> Result<CowBytes<'a>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>( deserializer: D ) -> Result<CowBytes<'a>, <D as Deserializer<'de>>::Error>where D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
§impl<'a, 'k> IntoPrefixRange<'a, CowBytes<'k>> for CowBytes<'k>
impl<'a, 'k> IntoPrefixRange<'a, CowBytes<'k>> for CowBytes<'k>
§fn to_prefix_range(&'a self) -> RangeRef<'a, CowBytes<'k>, CowBytes<'k>>
fn to_prefix_range(&'a self) -> RangeRef<'a, CowBytes<'k>, CowBytes<'k>>
Returns the value as a prefix-range, which will match all values that
start with
self
.§impl<'k> Key<'k> for CowBytes<'k>
impl<'k> Key<'k> for CowBytes<'k>
§const CAN_OWN_BYTES: bool = true
const CAN_OWN_BYTES: bool = true
If true, this type can benefit from an owned
Vec<u8>
. This flag is
used as a hint of whether to attempt to do memcpy operations in some
decoding operations to avoid extra allocations.§fn from_ord_bytes<'b>(
bytes: ByteSource<'k, 'b>
) -> Result<CowBytes<'k>, <CowBytes<'k> as KeyEncoding<CowBytes<'k>>>::Error>
fn from_ord_bytes<'b>( bytes: ByteSource<'k, 'b> ) -> Result<CowBytes<'k>, <CowBytes<'k> as KeyEncoding<CowBytes<'k>>>::Error>
Deserialize a sequence of bytes previously encoded with
KeyEncoding::as_ord_bytes
.§fn first_value() -> Result<Self, NextValueError>
fn first_value() -> Result<Self, NextValueError>
Return the first value in sequence for this type. Not all types
implement this.
§fn next_value(&self) -> Result<Self, NextValueError>
fn next_value(&self) -> Result<Self, NextValueError>
Return the next value in sequence for this type. Not all types implement
this. Instead of wrapping/overflowing, None should be returned.
§impl<'k> KeyEncoding<CowBytes<'k>> for &'k [u8]
impl<'k> KeyEncoding<CowBytes<'k>> for &'k [u8]
§type Error = Infallible
type Error = Infallible
The error type that can be produced by either serialization or
deserialization.
§const LENGTH: Option<usize> = None
const LENGTH: Option<usize> = None
The size of the key, if constant. If this type doesn’t produce the same
number of bytes for each value, this should be
None
.§fn describe<Visitor>(visitor: &mut Visitor)where
Visitor: KeyVisitor,
fn describe<Visitor>(visitor: &mut Visitor)where Visitor: KeyVisitor,
Describes this type by invoking functions on
visitor
describing the
key being encoded. Read more§fn as_ord_bytes(
&self
) -> Result<Cow<'_, [u8]>, <&'k [u8] as KeyEncoding<CowBytes<'k>>>::Error>
fn as_ord_bytes( &self ) -> Result<Cow<'_, [u8]>, <&'k [u8] as KeyEncoding<CowBytes<'k>>>::Error>
Convert
self
into a Cow<'_, [u8]>
containing bytes that are able to be
compared via memcmp
in a way that is comptaible with its own Ord
implementation.§impl<'k> KeyEncoding<CowBytes<'k>> for CowBytes<'k>
impl<'k> KeyEncoding<CowBytes<'k>> for CowBytes<'k>
§type Error = Infallible
type Error = Infallible
The error type that can be produced by either serialization or
deserialization.
§const LENGTH: Option<usize> = None
const LENGTH: Option<usize> = None
The size of the key, if constant. If this type doesn’t produce the same
number of bytes for each value, this should be
None
.§fn describe<Visitor>(visitor: &mut Visitor)where
Visitor: KeyVisitor,
fn describe<Visitor>(visitor: &mut Visitor)where Visitor: KeyVisitor,
Describes this type by invoking functions on
visitor
describing the
key being encoded. Read more§fn as_ord_bytes(
&self
) -> Result<Cow<'_, [u8]>, <CowBytes<'k> as KeyEncoding<CowBytes<'k>>>::Error>
fn as_ord_bytes( &self ) -> Result<Cow<'_, [u8]>, <CowBytes<'k> as KeyEncoding<CowBytes<'k>>>::Error>
Convert
self
into a Cow<'_, [u8]>
containing bytes that are able to be
compared via memcmp
in a way that is comptaible with its own Ord
implementation.§impl<'a> Ord for CowBytes<'a>
impl<'a> Ord for CowBytes<'a>
§impl<'a, 'b, const N: usize> PartialEq<&'b [u8; N]> for CowBytes<'a>
impl<'a, 'b, const N: usize> PartialEq<&'b [u8; N]> for CowBytes<'a>
§impl<'a, const SIZE: usize> PartialEq<[u8; SIZE]> for CowBytes<'a>
impl<'a, const SIZE: usize> PartialEq<[u8; SIZE]> for CowBytes<'a>
§impl<'a> PartialEq<CowBytes<'a>> for CowBytes<'a>
impl<'a> PartialEq<CowBytes<'a>> for CowBytes<'a>
§impl<'b, 'a> PartialOrd<&'b [u8]> for CowBytes<'a>
impl<'b, 'a> PartialOrd<&'b [u8]> for CowBytes<'a>
§fn partial_cmp(&self, other: &&'b [u8]) -> Option<Ordering>
fn partial_cmp(&self, other: &&'b [u8]) -> Option<Ordering>
1.0.0 · source§fn 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, 'b, const SIZE: usize> PartialOrd<&'b [u8; SIZE]> for CowBytes<'a>
impl<'a, 'b, const SIZE: usize> PartialOrd<&'b [u8; SIZE]> for CowBytes<'a>
1.0.0 · source§fn 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> PartialOrd<[u8]> for CowBytes<'a>
impl<'a> PartialOrd<[u8]> for CowBytes<'a>
§fn partial_cmp(&self, other: &[u8]) -> Option<Ordering>
fn partial_cmp(&self, other: &[u8]) -> Option<Ordering>
1.0.0 · source§fn 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> PartialOrd<CowBytes<'a>> for CowBytes<'a>
impl<'a> PartialOrd<CowBytes<'a>> for CowBytes<'a>
§fn partial_cmp(&self, other: &CowBytes<'a>) -> Option<Ordering>
fn partial_cmp(&self, other: &CowBytes<'a>) -> Option<Ordering>
1.0.0 · source§fn 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> Serialize for CowBytes<'a>
impl<'a> Serialize for CowBytes<'a>
§fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>( &self, serializer: S ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where S: Serializer,
Serialize this value into the given Serde serializer. 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§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere T: 'a,
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
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.