MaybeOwned

Enum MaybeOwned 

Source
pub enum MaybeOwned<'a, TOwned, TBorrowed: ?Sized = TOwned> {
    Owned(TOwned),
    Borrowed(&'a TBorrowed),
}
Expand description

A value that may be owned or not. Similar to std::borrow::Cow but does not require Clone.

Variants§

§

Owned(TOwned)

An owned value.

§

Borrowed(&'a TBorrowed)

A borrowed value.

Trait Implementations§

Source§

impl<'a, TOwned, TBorrowed> Borrow<TBorrowed> for MaybeOwned<'a, TOwned, TBorrowed>
where TOwned: Borrow<TBorrowed>, TBorrowed: ?Sized,

Source§

fn borrow(&self) -> &TBorrowed

Immutably borrows from an owned value. Read more
Source§

impl<'a, TOwned, TBorrowed> Clone for MaybeOwned<'a, TOwned, TBorrowed>
where TOwned: Clone, TBorrowed: ?Sized,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a, TOwned: Debug, TBorrowed: Debug + ?Sized> Debug for MaybeOwned<'a, TOwned, TBorrowed>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'a, TOwned, TBorrowed> Deref for MaybeOwned<'a, TOwned, TBorrowed>
where TOwned: Borrow<TBorrowed>, TBorrowed: ?Sized,

Source§

type Target = TBorrowed

The resulting type after dereferencing.
Source§

fn deref(&self) -> &TBorrowed

Dereferences the value.
Source§

impl<'a, 'k, TOwned, TBorrowed> Key<'k> for MaybeOwned<'a, TOwned, TBorrowed>
where TBorrowed: KeyEncoding<TOwned, Error = TOwned::Error> + PartialEq + ?Sized, TOwned: Key<'k> + PartialEq<TBorrowed>,

Source§

const CAN_OWN_BYTES: bool = TOwned::CAN_OWN_BYTES

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<'e>(bytes: ByteSource<'k, 'e>) -> Result<Self, Self::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<'a, 'k, TOwned, TBorrowed> KeyEncoding for MaybeOwned<'a, TOwned, TBorrowed>
where TBorrowed: KeyEncoding<TOwned, Error = TOwned::Error> + PartialEq + ?Sized, TOwned: Key<'k> + PartialEq<TBorrowed>,

Source§

const LENGTH: Option<usize> = TBorrowed::LENGTH

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§

type Error = <TOwned as KeyEncoding>::Error

The error type that can be produced by either serialization or deserialization.
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]>, Self::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<'a, TOwned, TBorrowed> PartialEq<TBorrowed> for MaybeOwned<'a, TOwned, TBorrowed>
where TOwned: Borrow<TBorrowed>, TBorrowed: PartialEq + ?Sized,

Source§

fn eq(&self, other: &TBorrowed) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

impl<'a, TOwned, TBorrowed> PartialEq for MaybeOwned<'a, TOwned, TBorrowed>
where TOwned: Borrow<TBorrowed>, TBorrowed: PartialEq + ?Sized,

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

impl<'a, TOwned, TBorrowed> PartialOrd<TBorrowed> for MaybeOwned<'a, TOwned, TBorrowed>
where TOwned: Borrow<TBorrowed>, TBorrowed: PartialOrd + ?Sized,

Source§

fn partial_cmp(&self, other: &TBorrowed) -> 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

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

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

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

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

impl<'a, TOwned, TBorrowed> PartialOrd for MaybeOwned<'a, TOwned, TBorrowed>
where TOwned: Borrow<TBorrowed>, TBorrowed: PartialOrd + ?Sized,

Source§

fn partial_cmp(&self, other: &Self) -> 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

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

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

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

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

Auto Trait Implementations§

§

impl<'a, TOwned, TBorrowed> Freeze for MaybeOwned<'a, TOwned, TBorrowed>
where TOwned: Freeze, TBorrowed: ?Sized,

§

impl<'a, TOwned, TBorrowed> RefUnwindSafe for MaybeOwned<'a, TOwned, TBorrowed>
where TOwned: RefUnwindSafe, TBorrowed: RefUnwindSafe + ?Sized,

§

impl<'a, TOwned, TBorrowed> Send for MaybeOwned<'a, TOwned, TBorrowed>
where TOwned: Send, TBorrowed: Sync + ?Sized,

§

impl<'a, TOwned, TBorrowed> Sync for MaybeOwned<'a, TOwned, TBorrowed>
where TOwned: Sync, TBorrowed: Sync + ?Sized,

§

impl<'a, TOwned, TBorrowed> Unpin for MaybeOwned<'a, TOwned, TBorrowed>
where TOwned: Unpin, TBorrowed: ?Sized,

§

impl<'a, TOwned, TBorrowed> UnwindSafe for MaybeOwned<'a, TOwned, TBorrowed>
where TOwned: UnwindSafe, TBorrowed: RefUnwindSafe + ?Sized,

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
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
Source§

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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

Source§

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

Source§

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.