Start with the idea
src/main.rs defines the default binary and src/lib.rs defines the library target. Additional binaries and integration tests have conventional directories that keep tooling automatic.
Cargo recognizes conventional paths, which lets a small project grow without custom build configuration. src/main.rs is the default binary entry point. src/lib.rs defines a library target that other crates and integration tests can import. Additional binaries can live under src/bin/, while external tests live under tests/. These paths describe targets, not just folders for tidiness.
In the sample, demo::answer() calls the library from the binary. The name before the double colon is the library crate name, normally derived from the package name unless configured otherwise.
Keep learning, for free
The rest of this lesson is waiting for you.
Create a free account to read the complete explanation, see the infographic, explore the code, and try the exercises. All 742 lessons and algorithm steps are included.
No payment details. Your account opens the complete Academy.