Rust contains 2 identical (by api) vec modules:
http://doc.rust-lang.org/std/vec/index.html
http://doc.rust-lang.org/collections/vec/index.html
What are the differences? which is preferable to use?
The collections
crate is not meant to be used directly in general; you should use the std
crate instead.
std::vec
is just collections::vec
reexported; it is exactly the same module.
If you want to use Vec
, you don't even need to import it with use
, because it's part of the prelude. The items defined in the prelude are always imported implicitly. If you need to import other items from that module, write use std::vec::X;
instead of use collections::vec::X;
Why does collections
exist? It's made available for those who write Rust applications that don't run on an operating system, or applications that are operating systems. std
provides features that depend on an operating system, but some parts of std
don't; those were split into smaller crates that can be reused more easily. However, those crates are not going to be stabilized in the near future, whereas std
will be made stable for Rust 1.0, so unless you really need to avoid std
, just use std
.
You can tell the compiler that you don't want to use std
by adding #![no_std]
to your crate root.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With