Index and IndexMut allows using the map[x]
syntax to retrieve and mutate values in the map.
Both traits are implemented as wrappers around
get and get_mut, respectively.
The SparseMap::get now returns an Option<&V>
to accommodate the type needs of Index.
get_mut was added to retrieve mutable references
for IndexMut. Handing out mutable access to the
values inside the map is safe because the algorithm
for maintaining valid map entries doesn't depend
on the value stored in any of the pairs in dense. In
addition, Rust guarantees that the underlying
structure of the map is not changed while a mutable
reference is alive, so the internal swapping is not a
concern either :)
Index
andIndexMut
allows using themap[x]
syntax to retrieve and mutate values in the map. Both traits are implemented as wrappers aroundget
andget_mut
, respectively.The
SparseMap::get
now returns anOption<&V>
to accommodate the type needs ofIndex
.get_mut
was added to retrieve mutable references forIndexMut
. Handing out mutable access to the values inside the map is safe because the algorithm for maintaining valid map entries doesn't depend on the value stored in any of the pairs indense
. In addition, Rust guarantees that the underlying structure of the map is not changed while a mutable reference is alive, so the internal swapping is not a concern either :)Closes #9