"std :: vec" vs "collections :: vec"
Rust contains 2 identical modules (api) vec:
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?
source to share
The box is collections
not intended to be used directly; you have to use the box std
instead.
std::vec
is simply collections::vec
re-exported; 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 . Items defined in the prelude are always implicitly imported. If you need to import other elements from this module, write use std::vec::X;
insteaduse collections::vec::X;
Why does it exist collections
? It was made available to anyone writing Rust applications that do not run on an operating system or applications that are operating systems. std
Provides OS-dependent functions, but some parts std
do not work they were divided into smaller boxes that could be reused. However, these boxes won't stabilize in the near future, whereas they std
will be stable for Rust 1.0, so if you really don't need to avoid std
, just use std
.
You can tell the compiler what you don't want to use std
by adding #![no_std]
to your root directory.
source to share