问题
I'd like to write a library that's a thin wrapper around some of the functionality in BTreeMap. I'd prefer not to tightly couple it to that particular data structure though. Strictly speaking, I only need a subset of its functionality, something along the lines of the NavigableMap interface in Java. I was hoping to find an analogous trait I could use. I seem to recall that at some point there were traits like Map
and MutableMap
in the standard library, but they seem to be absent now.
Is there a crate that defines these? Or will they eventually be re-added to std?
回答1:
No, right now there's only Iterator. MutableMap
and Map
have been removed somewhere along the road to stabilization of std for Rust 1.0.
There have been various discussions about re-adding traits to std. See these discussions on Rust internals:
- Traits that should be in std, but aren’t
or (less recent but more specifically on collections):
- Collection Traits, Take 2
Bottom line: everybody wants some form of those traits in std but nobody wants to commit adding and supporting the wrong ones in the standard library until a clearer picture of what is ergonomic emerges.
来源:https://stackoverflow.com/questions/35159530/does-rust-have-collection-traits