mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-05 06:28:20 -04:00
feat(base): Add ObservableMap::len.
This patch implements `ObservableMap::len`, which is useful to count of values it contains.
This commit is contained in:
@@ -147,6 +147,11 @@ where
|
||||
|
||||
Some(self.values.remove(position))
|
||||
}
|
||||
|
||||
/// Get the number of values.
|
||||
pub(crate) fn len(&self) -> usize {
|
||||
self.mapping.len()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -295,4 +300,21 @@ mod tests {
|
||||
drop(map);
|
||||
assert_closed!(stream);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_len() {
|
||||
let mut map = ObservableMap::<char, char>::new();
|
||||
|
||||
assert_eq!(map.len(), 0);
|
||||
|
||||
map.insert('a', 'e');
|
||||
map.insert('b', 'f');
|
||||
map.insert('c', 'g');
|
||||
|
||||
assert_eq!(map.len(), 3);
|
||||
|
||||
map.remove(&'b');
|
||||
|
||||
assert_eq!(map.len(), 2);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user