Rust anatomy: Difference between revisions
From wikinotes
(→Crates) |
No edit summary |
||
Line 22: | Line 22: | ||
* it may have multiple executable crates | * it may have multiple executable crates | ||
* it may only have one library crate | * it may only have one library crate | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
Line 37: | Line 31: | ||
Cargo.lock | Cargo.lock | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</blockquote><!-- Packages --> | |||
== Crates == | |||
<blockquote> | |||
A crate can be either | |||
* a library (has <code>src/lib.rs</code> entrypoint) | |||
* an executable (has <code>src/main.rs</code> entrypoint) | |||
</blockquote><!-- Crates --> | </blockquote><!-- Crates --> | ||
Revision as of 14:14, 8 February 2023
Project Components
A rust project comprises of
packages build/test/share a collection of crates crates tree of modules that build a single library, or executable modules organize scope/privacy of paths paths files ? Packages
A package is a collection of crates.
- it may have multiple executable crates
- it may only have one library crate
myproject/ src/ main.rs Cargo.toml Cargo.lockCrates
A crate can be either
- a library (has
src/lib.rs
entrypoint)- an executable (has
src/main.rs
entrypoint)Modules
Modules contain groups of related srcfiles.
modules are private to their parents by default, and public to their child modules.
the name/namespace of the module mirrors it's filesystem location.
theuse
keyword can merge a module or one of it's elements into the current namespace.See more details in rust modules.