Reputation: 1393
I am trying to use BitSet
data structure, but it gives me a compile error saying it was not able to find the BitSet.
Has std::collections::BitSet
been released in the stable version?
use std::collections::BitSet;
fn main() {
println!("Hello, world!");
}
Produces the error:
error[E0432]: unresolved import `std::collections::BitSet`
--> src/main.rs:1:5
|
1 | use std::collections::BitSet;
| ^^^^^^^^^^^^^^^^^^^^^^^^ no `BitSet` in `collections`
Upvotes: 12
Views: 10820
Reputation: 3545
It seems that BitSet
existed in Rust 1.3.0, which is very old, but was already deprecated at that time and finally removed by this commit.
Instead, you can use bit-set
crate, as suggested by the deprecation message above. There's also 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);
}
You'll have to add a dependency to the bit-set
crate in some way. It's easy if you're using Cargo:
[package]
name = "foo"
version = "0.1.0"
authors = ["Foo Bar <[email protected]>"]
[dependencies]
bit-set = "0.4.0" # Add this line
If you're using the official Rust Playground, you can automatically use bit-set
, because it is one of the top 100 downloaded crates or a dependency of one of them.
Upvotes: 12