mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 21:21:11 +00:00
Add map and try_map methods to BoundedBTreeMap (#11869)
* Add map and try_map methods to BoundedBTreeMap * Undo changes to basic_authorship.rs * Remove unwrap and use unchecked_from instead * Add iter_mut() method * Remove map functions and add docs to iter_mut * fmt Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
@@ -161,6 +161,13 @@ where
|
||||
{
|
||||
self.0.remove_entry(key)
|
||||
}
|
||||
|
||||
/// Gets a mutable iterator over the entries of the map, sorted by key.
|
||||
///
|
||||
/// See [`BTreeMap::iter_mut`] for more information.
|
||||
pub fn iter_mut(&mut self) -> sp_std::collections::btree_map::IterMut<K, V> {
|
||||
self.0.iter_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<K, V, S> Default for BoundedBTreeMap<K, V, S>
|
||||
@@ -508,7 +515,7 @@ pub mod test {
|
||||
b1.iter().map(|(k, v)| (k + 1, *v)).take(2).try_collect().unwrap();
|
||||
assert_eq!(b2.into_iter().map(|(k, _)| k).collect::<Vec<_>>(), vec![2, 3]);
|
||||
|
||||
// but these worn't work
|
||||
// but these won't work
|
||||
let b2: Result<BoundedBTreeMap<u32, (), ConstU32<3>>, _> =
|
||||
b1.iter().map(|(k, v)| (k + 1, *v)).try_collect();
|
||||
assert!(b2.is_err());
|
||||
@@ -517,4 +524,17 @@ pub mod test {
|
||||
b1.iter().map(|(k, v)| (k + 1, *v)).skip(2).try_collect();
|
||||
assert!(b2.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iter_mut() {
|
||||
let mut b1: BoundedBTreeMap<u8, u8, ConstU32<7>> =
|
||||
[1, 2, 3, 4].into_iter().map(|k| (k, k)).try_collect().unwrap();
|
||||
|
||||
let b2: BoundedBTreeMap<u8, u8, ConstU32<7>> =
|
||||
[1, 2, 3, 4].into_iter().map(|k| (k, k * 2)).try_collect().unwrap();
|
||||
|
||||
b1.iter_mut().for_each(|(_, v)| *v *= 2);
|
||||
|
||||
assert_eq!(b1, b2);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user