Does Rust have Collection traits?

▼魔方 西西 提交于 2019-12-22 03:24:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!