3 ms·
Sweet and to the point, thanks! Also of note, aside from finding the crate root and dependent crates (these are passed explicitly to the compiler, from Cargo m
by Tobu 6y ago
Sweet and to the point, thanks!
Also of note, aside from finding the crate root and dependent crates (these are passed explicitly to the compiler, from Cargo most of the time), all of this is strictly part of the Rust language, and handled by the compiler. I find the language model really clear and explicit. I would not touch it, aside from discouraging the use of mod.rs.
I think there's room for an article that expands into Cargo's convention-based source model, which is a bit trickier. A package directory can contain multiple crates: at most one library crate rooted in `src/lib.rs`, but also the various executables that are discovered from the filesystem: src/bin/*.rs, src/main.rs, examples, the test binary, bench binaries… These are crates of their own, with examples and benches needing a library crate to be enabled to access files in the src/ folder (without ugly hacks).