我正在尝试使用BitSet
数据结构,但它给了我一个编译错误,说它无法找到BitSet.
已经在稳定版本中发布了std::collections::BitSet
?
use std::collections::BitSet;
fn main() {
println!("Hello, world!");
}
产生错误:
error[E0432]: unresolved import `std::collections::BitSet`
--> src/main.rs:1:5
|
1 | use std::collections::BitSet;
| ^^^^^^^^^^^^^^^^^^^^^^^^ no `BitSet` in `collections`
似乎BitSet
existed in Rust 1.3.0, which is very old,但当时已经弃用,最后removed by this commit。
相反,您可以使用bit-set
crate,如上面的弃用消息所示。还有documentation。
extern crate bit_set;
use bit_set::BitSet;
fn main() {
let mut s = BitSet::new();
s.insert(32);
s.insert(37);
s.insert(3);
println!("s = {:?}", s);
}
您必须以某种方式向bit-set
箱添加依赖项。如果你使用货物很容易:
[package]
name = "foo"
version = "0.1.0"
authors = ["Foo Bar <[email protected]>"]
[dependencies]
bit-set = "0.4.0" # Add this line
如果你正在使用the official Rust Playground,你可以自动使用bit-set
,因为它是the top 100 downloaded crates之一或其中一个的依赖。