I'm curious is there a difference between these two modules in practice? And if not, why have these two duplicates then?
Asked
Active
Viewed 391 times
3
-
1See also http://stackoverflow.com/questions/30463162/use-of-undeclared-type-or-module-corefmtdisplay – Shepmaster May 28 '15 at 13:39
1 Answers
7
std::rc::Rc
is just a re-export of alloc::rc::Rc
. You can see in src/std/lib.rs that the whole rc
module is re-exported: pub use alloc::rc;
The alloc
crate is for any kind of memory allocations. Reference counted, Boxed, raw allocations and general access to the underlying allocator (often jemalloc
in Rust). Since the Rc
type is such a common type that it should exist in the standard library, but the alloc
crate should not be a part of the standard library, just the rc
module of alloc
is re-exported to the standard library. This saves the user from having to care about the alloc
crate, and instead offers a clean standard library without odd stuff that is prone to be uncomfortable to use.

oli_obk
- 28,729
- 6
- 82
- 98
-
-
@DanielFath: It's just a matter of flexibility/convenience. On the one hand, it's more flexible to have multiple low-level crates (`core`, `alloc`, `collections`, ...) so that low-level users (such as kernel writers) can cherry pick only the crates that can be used in their context and on the other hand it's more convenient for users to have a single crate to reach for (`std`). – Matthieu M. May 31 '15 at 14:07