Skip to content

Project Structure

Ashish Kankal edited this page Dec 30, 2020 · 2 revisions

Folder structure to follow for the modules

.
├── Cargo.lock
├── Cargo.toml
├── src/
│   ├── lib.rs
│   ├── module_1.rs
│   ├── module_2.rs
│   ├── module_3.rs
│   ├── ...
│   ├── module_1/
│   ├── module_2/
│   ├── module_3/
│   ├── ...
├── examples/
│   ├── main.rs
│   │── ssl_tls/
│   │   │── main.rs
│   │   └── sub_main.rs
│   └── module_2/
│       ├── main.rs
│       └── sub_main.rs
│   └── ../
└── tests/
    ├── some-integration-tests.rs

Adding a new module (a single module that is small in size and can be written in a single file)

  1. Create a [module_name].rsinsrc` folder
  2. Add pub mod [module_name]; in lib.rs

Adding a new module which has multiple sub modules

  1. Create a [module_name]/ folder.
  2. Create [submodule_name].rs for respective submodules inside the folder created in step 1.
  3. Create a [module_name].rs in src folder.
  4. Add pub mod [submodule_name]; in [module_name].rs for each submodule.
  5. Add pub mod [module_name]; in lib.rs

Adding Examples

  1. Create [module_name]_example.rs or [submodule_name]_example.rs in the examples folder
  2. Import the crate to demonstrate the associated functionalities.
  3. Use command cargo run --example [filename].rs to run the example.