Struct typedmap::hashmap::TypedKeyValueMutRef [−][src]
Represents mutably borrowed pair of key and value.
Implementations
impl<'a, Marker> TypedKeyValueMutRef<'a, Marker>
[src]
pub fn downcast_key_ref<K: 'static + TypedMapKey<Marker>>(
&self
) -> Option<&'a K>
[src]
&self
) -> Option<&'a K>
Downcast key to reference of K
. Returns None
if not possible.
pub fn downcast_value_mut<'b, V: 'static + Any>(
&'b mut self
) -> Option<&'b mut V> where
'a: 'b,
[src]
&'b mut self
) -> Option<&'b mut V> where
'a: 'b,
Downcast value to type V
. Returns None
if not possible.
Note: this function borrows mutably self, and returns mutable reference with lifetime
bounded by that borrow. If you need to obtain mutable reference with hashmap bounded
lifetime (’a), then use downcast_value
function.
pub fn downcast_value<V: 'static + Any>(self) -> Result<&'a mut V, Self>
[src]
Tries to cast value to mutable reference of V consuming self. This allows to return mutable reference with ’a lifetime which may be useful when collecting mutable references.
Examples:
use typedmap::TypedMap; use typedmap::TypedMapKey; #[derive(Hash, PartialEq, Eq, Debug)] struct Key(usize); #[derive(Hash, PartialEq, Eq, Debug)] struct SKey(&'static str); impl TypedMapKey for Key { type Value = u32; } impl TypedMapKey for SKey { type Value = usize; } let mut map: TypedMap = TypedMap::new(); map.insert(Key(3), 3); map.insert(SKey("four"), 4); let v: Vec<&mut u32> = map .iter_mut() .flat_map(|kv| kv.downcast_value::<u32>().ok()) .collect(); assert_eq!(*v[0], 3); assert_eq!(v.len(), 1);
pub fn downcast_pair_mut<'b, K: 'static + TypedMapKey<Marker>>(
&'b mut self
) -> Option<(&'b K, &'b mut K::Value)> where
'a: 'b,
[src]
&'b mut self
) -> Option<(&'b K, &'b mut K::Value)> where
'a: 'b,
Downcast key to type K
and value to type K::Value
. Returns None
if not possible.
Note: this function borrows mutably self, and returns mutable reference with lifetime
bounded by that borrow. If you need to obtain mutable reference with hashmap bounded
lifetime (’a), then use downcast_pair
function.
pub fn downcast_pair<K: 'static + TypedMapKey<Marker>>(
self
) -> Result<(&'a K, &'a mut K::Value), Self>
[src]
self
) -> Result<(&'a K, &'a mut K::Value), Self>
Tries to cast self to key K and value K::Value consuming self. This allows to return references with ’a lifetime which may be useful when collecting references to Vec.
Examples:
use typedmap::TypedMap; use typedmap::TypedMapKey; #[derive(Hash, PartialEq, Eq, Debug)] struct Key(usize); #[derive(Hash, PartialEq, Eq, Debug)] struct SKey(&'static str); impl TypedMapKey for Key { type Value = u32; } impl TypedMapKey for SKey { type Value = usize; } let mut map: TypedMap = TypedMap::new(); map.insert(Key(3), 3); map.insert(SKey("four"), 4); let v: Vec<(&Key, &mut u32)> = map .iter_mut() .flat_map(|kv| kv.downcast_pair::<Key>().ok()) .collect(); assert_eq!(*v[0].0, Key(3)); assert_eq!(*v[0].1, 3); assert_eq!(v.len(), 1);
Trait Implementations
impl<M> Debug for TypedKeyValueMutRef<'_, M>
[src]
Auto Trait Implementations
impl<'a, Marker> !RefUnwindSafe for TypedKeyValueMutRef<'a, Marker>
impl<'a, Marker> !Send for TypedKeyValueMutRef<'a, Marker>
impl<'a, Marker> !Sync for TypedKeyValueMutRef<'a, Marker>
impl<'a, Marker> Unpin for TypedKeyValueMutRef<'a, Marker> where
Marker: Unpin,
Marker: Unpin,
impl<'a, Marker> !UnwindSafe for TypedKeyValueMutRef<'a, Marker>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,