How do I tell Cargo to create files other than main.rs?

Here is my directory structure:

lowks@lowkster ~/src/rustlang/gettingrusty $ tree .
.
├── Cargo.lock
├── Cargo.toml
├── foo.txt
├── src
│   ├── boolean_example.rs
│   ├── function_goodbye_world.rs
│   ├── listdir.rs
│   ├── looping.rs
│   ├── main.rs
│   ├── pattern_match.rs
│   └── write_to_file.rs
└── target
    ├── build
    ├── deps
    ├── examples
    ├── gettingrusty
    └── native

6 directories, 11 files

When I start the “cargo assembly”, it seems to be just building main.rs. How do I change Cargo.toml to create the rest of the files?

+6
source share
2 answers

The Rust compiler compiles all files at once to build crate , which is an executable or library. To add files to your mailbox, add moditems to your root directory (here, main.rs) or to other modules:

mod boolean_example;
mod function_goodbye_world;
mod listdir;
mod looping;
mod pattern_match;
mod write_to_file;

, , . , foo looping, looping::foo.

use . , use looping::foo;, foo looping::foo.

. .

+6

other.rs bin src (./src/bin/other.rs). cargo build --bin other cargo run --bin other

+1

Source: https://habr.com/ru/post/1568700/


All Articles