Skip to content

Implicit zero for unknown entries

Compare
Choose a tag to compare
@coriolinus coriolinus released this 19 May 09:03
· 127 commits to master since this release

Counters now implement Index and IndexMut, so they can have implicit zero counts. In other words:

# use counter::Counter;
let counter = "aaa".chars().collect::<Counter<_>>();
assert_eq!(counter[&'b'], 0);
// panics
// assert_eq!((*counter)[&'b'], 0);

This is a breaking change, causing a minor version bump, because it is not impossible that previous code depended on indexing panicing for unknown entries. Code which does not panic as part of its intended control flow will not be affected.