Enum bonsaidb::core::connection::MaybeOwned
pub enum MaybeOwned<'a, TOwned, TBorrowed = TOwned>where
TBorrowed: ?Sized,{
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§
Trait Implementations§
§impl<'a, TOwned, TBorrowed> Borrow<TBorrowed> for MaybeOwned<'a, TOwned, TBorrowed>where
TOwned: Borrow<TBorrowed>,
TBorrowed: ?Sized,
impl<'a, TOwned, TBorrowed> Borrow<TBorrowed> for MaybeOwned<'a, TOwned, TBorrowed>where TOwned: Borrow<TBorrowed>, TBorrowed: ?Sized,
§fn borrow(&self) -> &TBorrowed
fn borrow(&self) -> &TBorrowed
Immutably borrows from an owned value. Read more
§impl<'a, TOwned, TBorrowed> Clone for MaybeOwned<'a, TOwned, TBorrowed>where
TOwned: Clone,
TBorrowed: ?Sized,
impl<'a, TOwned, TBorrowed> Clone for MaybeOwned<'a, TOwned, TBorrowed>where TOwned: Clone, TBorrowed: ?Sized,
§fn clone(&self) -> MaybeOwned<'a, TOwned, TBorrowed>
fn clone(&self) -> MaybeOwned<'a, TOwned, TBorrowed>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read more§impl<'a, TOwned, TBorrowed> Debug for MaybeOwned<'a, TOwned, TBorrowed>where
TOwned: Debug,
TBorrowed: Debug + ?Sized,
impl<'a, TOwned, TBorrowed> Debug for MaybeOwned<'a, TOwned, TBorrowed>where TOwned: Debug, TBorrowed: Debug + ?Sized,
§impl<'a, TOwned, TBorrowed> Deref for MaybeOwned<'a, TOwned, TBorrowed>where
TOwned: Borrow<TBorrowed>,
TBorrowed: ?Sized,
impl<'a, TOwned, TBorrowed> Deref for MaybeOwned<'a, TOwned, TBorrowed>where TOwned: Borrow<TBorrowed>, TBorrowed: ?Sized,
§fn deref(&self) -> &TBorrowed
fn deref(&self) -> &TBorrowed
Dereferences the value.
§impl<'a, 'k, TOwned, TBorrowed> Key<'k> for MaybeOwned<'a, TOwned, TBorrowed>where
TBorrowed: KeyEncoding<TOwned, Error = <TOwned as KeyEncoding<TOwned>>::Error> + PartialEq<TBorrowed> + ?Sized,
TOwned: Key<'k> + PartialEq<TBorrowed>,
impl<'a, 'k, TOwned, TBorrowed> Key<'k> for MaybeOwned<'a, TOwned, TBorrowed>where TBorrowed: KeyEncoding<TOwned, Error = <TOwned as KeyEncoding<TOwned>>::Error> + PartialEq<TBorrowed> + ?Sized, TOwned: Key<'k> + PartialEq<TBorrowed>,
§const CAN_OWN_BYTES: bool = TOwned::CAN_OWN_BYTES
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.§fn from_ord_bytes<'e>(
bytes: ByteSource<'k, 'e>
) -> Result<MaybeOwned<'a, TOwned, TBorrowed>, <MaybeOwned<'a, TOwned, TBorrowed> as KeyEncoding<MaybeOwned<'a, TOwned, TBorrowed>>>::Error>
fn from_ord_bytes<'e>( bytes: ByteSource<'k, 'e> ) -> Result<MaybeOwned<'a, TOwned, TBorrowed>, <MaybeOwned<'a, TOwned, TBorrowed> as KeyEncoding<MaybeOwned<'a, TOwned, TBorrowed>>>::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<'a, 'k, TOwned, TBorrowed> KeyEncoding<MaybeOwned<'a, TOwned, TBorrowed>> for MaybeOwned<'a, TOwned, TBorrowed>where
TBorrowed: KeyEncoding<TOwned, Error = <TOwned as KeyEncoding<TOwned>>::Error> + PartialEq<TBorrowed> + ?Sized,
TOwned: Key<'k> + PartialEq<TBorrowed>,
impl<'a, 'k, TOwned, TBorrowed> KeyEncoding<MaybeOwned<'a, TOwned, TBorrowed>> for MaybeOwned<'a, TOwned, TBorrowed>where TBorrowed: KeyEncoding<TOwned, Error = <TOwned as KeyEncoding<TOwned>>::Error> + PartialEq<TBorrowed> + ?Sized, TOwned: Key<'k> + PartialEq<TBorrowed>,
§type Error = <TOwned as KeyEncoding<TOwned>>::Error
type Error = <TOwned as KeyEncoding<TOwned>>::Error
The error type that can be produced by either serialization or
deserialization.
§const LENGTH: Option<usize> = TBorrowed::LENGTH
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
.§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]>, <MaybeOwned<'a, TOwned, TBorrowed> as KeyEncoding<MaybeOwned<'a, TOwned, TBorrowed>>>::Error>
fn as_ord_bytes( &self ) -> Result<Cow<'_, [u8]>, <MaybeOwned<'a, TOwned, TBorrowed> as KeyEncoding<MaybeOwned<'a, TOwned, TBorrowed>>>::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, TOwned, TBorrowed> PartialEq<MaybeOwned<'a, TOwned, TBorrowed>> for MaybeOwned<'a, TOwned, TBorrowed>where
TOwned: Borrow<TBorrowed>,
TBorrowed: PartialEq<TBorrowed> + ?Sized,
impl<'a, TOwned, TBorrowed> PartialEq<MaybeOwned<'a, TOwned, TBorrowed>> for MaybeOwned<'a, TOwned, TBorrowed>where TOwned: Borrow<TBorrowed>, TBorrowed: PartialEq<TBorrowed> + ?Sized,
§fn eq(&self, other: &MaybeOwned<'a, TOwned, TBorrowed>) -> bool
fn eq(&self, other: &MaybeOwned<'a, TOwned, TBorrowed>) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.§impl<'a, TOwned, TBorrowed> PartialEq<TBorrowed> for MaybeOwned<'a, TOwned, TBorrowed>where
TOwned: Borrow<TBorrowed>,
TBorrowed: PartialEq<TBorrowed> + ?Sized,
impl<'a, TOwned, TBorrowed> PartialEq<TBorrowed> for MaybeOwned<'a, TOwned, TBorrowed>where TOwned: Borrow<TBorrowed>, TBorrowed: PartialEq<TBorrowed> + ?Sized,
§impl<'a, TOwned, TBorrowed> PartialOrd<MaybeOwned<'a, TOwned, TBorrowed>> for MaybeOwned<'a, TOwned, TBorrowed>where
TOwned: Borrow<TBorrowed>,
TBorrowed: PartialOrd<TBorrowed> + ?Sized,
impl<'a, TOwned, TBorrowed> PartialOrd<MaybeOwned<'a, TOwned, TBorrowed>> for MaybeOwned<'a, TOwned, TBorrowed>where TOwned: Borrow<TBorrowed>, TBorrowed: PartialOrd<TBorrowed> + ?Sized,
§fn partial_cmp(
&self,
other: &MaybeOwned<'a, TOwned, TBorrowed>
) -> Option<Ordering>
fn partial_cmp( &self, other: &MaybeOwned<'a, TOwned, TBorrowed> ) -> 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, TOwned, TBorrowed> PartialOrd<TBorrowed> for MaybeOwned<'a, TOwned, TBorrowed>where
TOwned: Borrow<TBorrowed>,
TBorrowed: PartialOrd<TBorrowed> + ?Sized,
impl<'a, TOwned, TBorrowed> PartialOrd<TBorrowed> for MaybeOwned<'a, TOwned, TBorrowed>where TOwned: Borrow<TBorrowed>, TBorrowed: PartialOrd<TBorrowed> + ?Sized,
§fn partial_cmp(&self, other: &TBorrowed) -> Option<Ordering>
fn partial_cmp(&self, other: &TBorrowed) -> 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 moreAuto Trait Implementations§
impl<'a, TOwned, TBorrowed: ?Sized> RefUnwindSafe for MaybeOwned<'a, TOwned, TBorrowed>where TBorrowed: RefUnwindSafe, TOwned: RefUnwindSafe,
impl<'a, TOwned, TBorrowed: ?Sized> Send for MaybeOwned<'a, TOwned, TBorrowed>where TBorrowed: Sync, TOwned: Send,
impl<'a, TOwned, TBorrowed: ?Sized> Sync for MaybeOwned<'a, TOwned, TBorrowed>where TBorrowed: Sync, TOwned: Sync,
impl<'a, TOwned, TBorrowed: ?Sized> Unpin for MaybeOwned<'a, TOwned, TBorrowed>where TOwned: Unpin,
impl<'a, TOwned, TBorrowed: ?Sized> UnwindSafe for MaybeOwned<'a, TOwned, TBorrowed>where TBorrowed: RefUnwindSafe, TOwned: UnwindSafe,
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