简体   繁体   English

如何在稳定的Rust中使用std :: collections :: BitSet?

[英]How do I use std::collections::BitSet in stable Rust?

I am trying to use BitSet data structure, but it gives me a compile error saying it was not able to find the BitSet. 我正在尝试使用BitSet数据结构,但是它给我一个编译错误,提示它无法找到BitSet. Has std::collections::BitSet been released in the stable version? std::collections::BitSet已在稳定版本中发布?

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`

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 . 似乎BitSet 存在于Rust 1.3.0中,它非常老 ,但是那时已经不推荐使用,并最终由commit删除

Instead, you can use bit-set crate , as suggested by the deprecation message above. 取而代之的是,您可以按照上面的弃用消息的建议使用bit-set crate 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. 您必须以某种方式将依赖项添加bit-set板箱中。 It's easy if you're using Cargo: 如果您使用货运,这很简单:

[package]
name = "foo"
version = "0.1.0"
authors = ["Foo Bar <foo@example.com>"]

[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. 如果您使用的是官方的Rust Playground ,则可以自动使用bit-set ,因为它是下载的前100个板条箱之一或其中之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM