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>
impl<Key> KeyWrapper<'_, Key>
sourcepub fn into_owned(self) -> Keywhere
Key: Clone,
pub fn into_owned(self) -> Keywhere
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);sourcepub fn is_borrowed(&self) -> bool
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());Trait Implementations§
source§impl<'map, Key: Clone> Clone for KeyWrapper<'map, Key>
impl<'map, Key: Clone> Clone for KeyWrapper<'map, Key>
source§fn clone(&self) -> KeyWrapper<'map, Key>
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)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl<'map, Key: Debug> Debug for KeyWrapper<'map, Key>
impl<'map, Key: Debug> Debug for KeyWrapper<'map, Key>
source§impl<'map, Key: Hash> Hash for KeyWrapper<'map, Key>
impl<'map, Key: Hash> Hash for KeyWrapper<'map, Key>
source§impl<'map, Key: PartialEq> PartialEq<KeyWrapper<'map, Key>> for KeyWrapper<'map, Key>
impl<'map, Key: PartialEq> PartialEq<KeyWrapper<'map, Key>> for KeyWrapper<'map, Key>
source§fn eq(&self, other: &KeyWrapper<'map, Key>) -> bool
fn eq(&self, other: &KeyWrapper<'map, Key>) -> bool
This method tests for
self and other values to be equal, and is used
by ==.