Vector – “STD:: VEC” vs “Collections:: VEC”

Rust contains two identical (via API) VEC modules:

http://doc.rust-lang.org/std/vec/index.html http://doc.rust-lang.org/collections/vec/index.html

What's the difference? Which is better?

Solution

The collection box does not mean direct use; You should use STD crit instead

STD:: VEC is just Collections:: VEC reexported; It is an identical module

If you want to use VEC, you don't even need to use it to import it, because it's part of prelude Items defined in the prelude are always imported implicitly If you need to import other projects from this module, use STD:: VEC:: X; Instead of using collections:: VEC:: X;

Why do collections exist? It is suitable for users who write rust applications or operating system applications that do not run on the operating system STD provides operating system dependent functions, but some parts of STD do not; Those that are split into smaller crates can be reused more easily However, these crates will not be stable in the near future, and STD will be stable for rust 1.0, so unless you really need to avoid STD, just use STD

You can add #! [no_std] to tell the compiler that you don't want to use STD

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>