why is the str datatype declared in three different spaces ?
core - alloc - std
why what is the point ?
why is the str datatype declared in three different spaces ?
core - alloc - std
why what is the point ?
The ones from alloc
and std
are just reexports of core
for convenience.
so str is originally from core ?
That is what reexports
tells us.
how do i know if something is re-exported ?
Copying over my answer from the duplicate on irlo in case it's useful:
Usually, reexports are documented as such, like in the prelude modules where they show up under a "Re-exports" header and are displayed as a pub use
. For #[doc(inline)]
d items, there's no (immediate[4]) indication in the docs whether an item is reexported or actually defined inline.
For the std facade specifically, it's by convention that items are reexported at the same path. If some item is available at both core::path::to::item
and std::path::to::item
, it's the same item, barring some niche historical edge cases[5].
Caveat: some things like core::arch
and core::atomic
are only conditionally available based on architecture support. ↩︎
noun: facade; an outward appearance that is maintained to conceal a less pleasant or creditable reality. ↩︎
This can have benefits to compile time (if the crate dependency graph is wide, it enables further parallelism) and for crates that only need a subset of functionality to only depend on that subset, even if the entire package is included into the build tree (which allows better build pipelining by not waiting on building functionality a library doesn't need as well as core types being versioned more stably than the veneer) ↩︎
If you click the source link, it takes you to the actual item definition, so you can know by looking at the path of the defining file, e.g. /src/core/...
or /src/std/...
. And if the source link isn't available but is for other items (e.g. on docs-rs), that's usually indication that it's a cross-crate reexport. ↩︎
The panic!
macro had subtly different behavior between core::panic!
and std::panic!
before the 2021 edition. This can mostly be attributed to macros not being use
able early in Rust's lifetime and core not having access to format!
, meaning the two macros had to be separately implemented with different functionality at the time. ↩︎
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.