Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
467 views
in Technique[技术] by (71.8m points)

bitarray - What is the proper way to use bit array in Rust?

I need a class with functionality equal to vector<bool> in C++. The Rust documentation tells about BitVec, but use std::collections::BitVec causes Unresolved import error during compiling. According to a pull request, BitVec has been removed. Is there any adequate replacement for it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There does not exist a dedicated bit-vector in the standard library and Vec<bool> is not specialized like C++'s vector<bool>. Rust advocates the use of external crates instead of building a huge standard library. The de-facto crate for this use case is bit-vec.

You appear to have found a link to an old standard library documentation: https://doc.rust-lang.org/1.2.0/std/collections/struct.BitVec.html. Note the 1.2.0 in the url! The current version of Rust is 1.25 (as of April 2018), which means that 1.2 is already more than two years old. Apart from that, BitVec is marked as unstable in the 1.2 docs; it was removed later.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...