]>
git.proxmox.com Git - rustc.git/blob - vendor/ordermap/src/mutable_keys.rs
3 use std
::hash
::BuildHasher
;
5 use super::{OrderMap, Equivalent}
;
7 pub struct PrivateMarker { }
9 /// Opt-in mutable access to keys.
11 /// These methods expose `&mut K`, mutable references to the key as it is stored
13 /// You are allowed to modify the keys in the hashmap **if the modifcation
14 /// does not change the key’s hash and equality**.
16 /// If keys are modified erronously, you can no longer look them up.
17 /// This is sound (memory safe) but a logical error hazard (just like
18 /// implementing PartialEq, Eq, or Hash incorrectly would be).
20 /// `use` this trait to enable its methods for `OrderMap`.
21 pub trait MutableKeys
{
25 /// Return item index, mutable reference to key and value
26 fn get_full_mut2
<Q
: ?Sized
>(&mut self, key
: &Q
)
27 -> Option
<(usize, &mut Self::Key
, &mut Self::Value
)>
28 where Q
: Hash
+ Equivalent
<Self::Key
>;
30 /// Scan through each key-value pair in the map and keep those where the
31 /// closure `keep` returns `true`.
33 /// The elements are visited in order, and remaining elements keep their
36 /// Computes in **O(n)** time (average).
37 fn retain2
<F
>(&mut self, keep
: F
)
38 where F
: FnMut(&mut Self::Key
, &mut Self::Value
) -> bool
;
40 /// This method is not useful in itself – it is there to “seal” the trait
41 /// for external implementation, so that we can add methods without
42 /// causing breaking changes.
43 fn __private_marker(&self) -> PrivateMarker
;
46 /// Opt-in mutable access to keys.
48 /// See [`MutableKeys`](trait.MutableKeys.html) for more information.
49 impl<K
, V
, S
> MutableKeys
for OrderMap
<K
, V
, S
>
55 fn get_full_mut2
<Q
: ?Sized
>(&mut self, key
: &Q
)
56 -> Option
<(usize, &mut K
, &mut V
)>
57 where Q
: Hash
+ Equivalent
<K
>,
59 if let Some((_
, found
)) = self.find(key
) {
60 let entry
= &mut self.entries
[found
];
61 Some((found
, &mut entry
.key
, &mut entry
.value
))
67 fn retain2
<F
>(&mut self, keep
: F
)
68 where F
: FnMut(&mut K
, &mut V
) -> bool
,
73 fn __private_marker(&self) -> PrivateMarker
{