pub enum KeyWrapper<'map, Key> {
    Borrowed(&'map Key),
    Owned(Key),
}
Expand description

A wrapper around a key that is either borrowed or owned.

This type is similar to std::borrow::Cow but does not require a Clone trait bound on the key.

Variants§

§

Borrowed(&'map Key)

An immutable reference to a key. This implies that the key is still associated to at least one value in the multimap.

§

Owned(Key)

An owned key. This will occur when a key is no longer associated with any values in the multimap.

Implementations§

source§

impl<Key> KeyWrapper<'_, Key>

source

pub fn into_owned(self) -> Key
where Key: Clone,

If the key wrapped is owned, it is returned. Otherwise, the borrowed key is cloned and returned.

§Examples
use ordered_multimap::list_ordered_multimap::KeyWrapper;

let borrowed = KeyWrapper::Borrowed(&0);
assert_eq!(borrowed.into_owned(), 0);

let owned = KeyWrapper::Owned(0);
assert_eq!(borrowed.into_owned(), 0);
source

pub fn is_borrowed(&self) -> bool

Returns whether the wrapped key is borrowed.

§Examples
use ordered_multimap::list_ordered_multimap::KeyWrapper;

let borrowed = KeyWrapper::Borrowed(&0);
assert!(borrowed.is_borrowed());

let owned = KeyWrapper::Owned(0);
assert!(!owned.is_borrowed());
source

pub fn is_owned(&self) -> bool

Returns whether the wrapped key is owned.

§Examples
use ordered_multimap::list_ordered_multimap::KeyWrapper;

let borrowed = KeyWrapper::Borrowed(&0);
assert!(!borrowed.is_owned());

let owned = KeyWrapper::Owned(0);
assert!(owned.is_owned());

Trait Implementations§

source§

impl<'map, Key: Clone> Clone for KeyWrapper<'map, Key>

source§

fn clone(&self) -> KeyWrapper<'map, Key>

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

impl<'map, Key: Debug> Debug for KeyWrapper<'map, Key>

source§

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

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

impl<'map, Key: Hash> Hash for KeyWrapper<'map, Key>

source§

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

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<'map, Key: PartialEq> PartialEq for KeyWrapper<'map, Key>

source§

fn eq(&self, other: &KeyWrapper<'map, Key>) -> 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.
source§

impl<'map, Key: Copy> Copy for KeyWrapper<'map, Key>

source§

impl<'map, Key: Eq> Eq for KeyWrapper<'map, Key>

source§

impl<'map, Key> StructuralPartialEq for KeyWrapper<'map, Key>

Auto Trait Implementations§

§

impl<'map, Key> Freeze for KeyWrapper<'map, Key>
where Key: Freeze,

§

impl<'map, Key> RefUnwindSafe for KeyWrapper<'map, Key>
where Key: RefUnwindSafe,

§

impl<'map, Key> Send for KeyWrapper<'map, Key>
where Key: Sync + Send,

§

impl<'map, Key> Sync for KeyWrapper<'map, Key>
where Key: Sync,

§

impl<'map, Key> Unpin for KeyWrapper<'map, Key>
where Key: Unpin,

§

impl<'map, Key> UnwindSafe for KeyWrapper<'map, Key>

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

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

Checks if this value is equivalent to the given key. 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> 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.