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§

§

impl<'a> CowBytes<'a>

pub fn into_cow(self) -> Cow<'a, [u8]>

Returns the underlying Cow.

pub fn into_vec(self) -> Vec<u8>

Returns the underlying Vec inside of the Cow, or clones the borrowed bytes into a new Vec..

pub fn as_slice(&self) -> &[u8]

Returns a slice of the contained data.

Methods from Deref<Target = Cow<'a, [u8]>>§

source

pub fn is_borrowed(&self) -> bool

🔬This is a nightly-only experimental API. (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());
source

pub fn is_owned(&self) -> bool

🔬This is a nightly-only experimental API. (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 · source

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<'a> Clone for CowBytes<'a>

§

fn clone(&self) -> CowBytes<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl<'a> Debug for CowBytes<'a>

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl<'a> Default for CowBytes<'a>

§

fn default() -> CowBytes<'a>

Returns the “default value” for a type. Read more
§

impl<'a> Deref for CowBytes<'a>

§

type Target = Cow<'a, [u8]>

The resulting type after dereferencing.
§

fn deref(&self) -> &<CowBytes<'a> as Deref>::Target

Dereferences the value.
§

impl<'a> DerefMut for CowBytes<'a>

§

fn deref_mut(&mut self) -> &mut <CowBytes<'a> as Deref>::Target

Mutably dereferences the value.
§

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>,

Deserialize this value from the given Serde deserializer. Read more
§

impl<'a> From<&'a [u8]> for CowBytes<'a>

§

fn from(buffer: &'a [u8]) -> CowBytes<'a>

Converts to this type from the input type.
§

impl<'a, const N: usize> From<&'a [u8; N]> for CowBytes<'a>

§

fn from(buffer: &'a [u8; N]) -> CowBytes<'a>

Converts to this type from the input type.
§

impl<'a, const N: usize> From<[u8; N]> for CowBytes<'a>

§

fn from(buffer: [u8; N]) -> CowBytes<'a>

Converts to this type from the input type.
§

impl<'a> From<Bytes> for CowBytes<'a>

§

fn from(bytes: Bytes) -> CowBytes<'a>

Converts to this type from the input type.
§

impl<'a> From<CowBytes<'a>> for ArcBytes<'a>

§

fn from(bytes: CowBytes<'a>) -> ArcBytes<'a>

Converts to this type from the input type.
§

impl<'a> From<CowBytes<'a>> for Bytes

§

fn from(bytes: CowBytes<'a>) -> Bytes

Converts to this type from the input type.
§

impl<'a> From<Vec<u8>> for CowBytes<'a>

§

fn from(buffer: Vec<u8>) -> CowBytes<'a>

Converts to this type from the input type.
§

impl<'a> Hash for CowBytes<'a>

§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<'a, 'k> IntoPrefixRange<'a, CowBytes<'k>> for CowBytes<'k>

source§

fn to_prefix_range(&'a self) -> RangeRef<'a, CowBytes<'k>>

Returns the value as a prefix-range, which will match all values that start with self.
source§

impl<'k> Key<'k> for CowBytes<'k>

source§

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.
source§

fn from_ord_bytes<'b>( bytes: ByteSource<'k, 'b> ) -> Result<CowBytes<'k>, <CowBytes<'k> as KeyEncoding>::Error>

Deserialize a sequence of bytes previously encoded with KeyEncoding::as_ord_bytes.
source§

fn first_value() -> Result<Self, NextValueError>

Return the first value in sequence for this type. Not all types implement this.
source§

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.
source§

impl<'k> KeyEncoding<CowBytes<'k>> for &'k [u8]

§

type Error = Infallible

The error type that can be produced by either serialization or deserialization.
source§

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.
source§

fn describe<Visitor>(visitor: &mut Visitor)
where Visitor: KeyVisitor,

Describes this type by invoking functions on visitor describing the key being encoded. Read more
source§

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.
source§

impl<'k> KeyEncoding for CowBytes<'k>

§

type Error = Infallible

The error type that can be produced by either serialization or deserialization.
source§

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.
source§

fn describe<Visitor>(visitor: &mut Visitor)
where Visitor: KeyVisitor,

Describes this type by invoking functions on visitor describing the key being encoded. Read more
source§

fn as_ord_bytes( &self ) -> Result<Cow<'_, [u8]>, <CowBytes<'k> as KeyEncoding>::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>

§

fn cmp(&self, other: &CowBytes<'a>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
§

impl<'a, 'b> PartialEq<&'b [u8]> for CowBytes<'a>

§

fn eq(&self, other: &&'b [u8]) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl<'a, 'b, const N: usize> PartialEq<&'b [u8; N]> for CowBytes<'a>

§

fn eq(&self, other: &&'b [u8; N]) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl<'a> PartialEq<[u8]> for CowBytes<'a>

§

fn eq(&self, other: &[u8]) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl<'a, const SIZE: usize> PartialEq<[u8; SIZE]> for CowBytes<'a>

§

fn eq(&self, other: &[u8; SIZE]) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl<'a> PartialEq for CowBytes<'a>

§

fn eq(&self, other: &CowBytes<'a>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl<'b, 'a> PartialOrd<&'b [u8]> for CowBytes<'a>

§

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 · source§

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 · source§

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
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater 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>

§

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 · source§

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 · source§

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
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl<'a> PartialOrd<[u8]> for CowBytes<'a>

§

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 · source§

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 · source§

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
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl<'a> PartialOrd for CowBytes<'a>

§

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 · source§

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 · source§

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
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl<'a> Serialize for CowBytes<'a>

§

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§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32 ) -> TaggedParser<'a, Implicit, Self, E>

source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CallHasher for T
where T: Hash + ?Sized,

§

fn get_hash<H, B>(value: &H, build_hasher: &B) -> u64
where H: Hash + ?Sized, B: BuildHasher,

§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,