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
sourceimpl<'map, Key> KeyWrapper<'map, Key>
impl<'map, Key> KeyWrapper<'map, Key>
sourcepub fn into_owned(self) -> Key where
Key: Clone,
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);
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
sourceimpl<'map, Key: Clone> Clone for KeyWrapper<'map, Key>
impl<'map, Key: Clone> Clone for KeyWrapper<'map, Key>
sourcefn clone(&self) -> KeyWrapper<'map, Key>
fn clone(&self) -> KeyWrapper<'map, Key>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<'map, Key: Debug> Debug for KeyWrapper<'map, Key>
impl<'map, Key: Debug> Debug for KeyWrapper<'map, Key>
sourceimpl<'map, Key: Hash> Hash for KeyWrapper<'map, Key>
impl<'map, Key: Hash> Hash for KeyWrapper<'map, Key>
sourceimpl<'map, Key: PartialEq> PartialEq<KeyWrapper<'map, Key>> for KeyWrapper<'map, Key>
impl<'map, Key: PartialEq> PartialEq<KeyWrapper<'map, Key>> for KeyWrapper<'map, Key>
sourcefn 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 ==
. Read more
sourcefn ne(&self, other: &KeyWrapper<'map, Key>) -> bool
fn ne(&self, other: &KeyWrapper<'map, Key>) -> bool
This method tests for !=
.
impl<'map, Key: Copy> Copy for KeyWrapper<'map, Key>
impl<'map, Key: Eq> Eq for KeyWrapper<'map, Key>
impl<'map, Key> StructuralEq for KeyWrapper<'map, Key>
impl<'map, Key> StructuralPartialEq for KeyWrapper<'map, Key>
Auto Trait Implementations
impl<'map, Key> RefUnwindSafe for KeyWrapper<'map, Key> where
Key: RefUnwindSafe,
impl<'map, Key> Send for KeyWrapper<'map, Key> where
Key: Send + Sync,
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> where
Key: UnwindSafe + RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more