feat(base): Add ObservableMap::len.

This patch implements `ObservableMap::len`, which is useful to count of
values it contains.
This commit is contained in:
Ivan Enderlin
2025-03-11 13:56:54 +01:00
parent 915cb13d45
commit 132f063769

View File

@@ -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);
}
}