Creating Modules

As this project will be bigger than just a couple of lines of code, things will be more organized if we split it up into modules. To do this, make a new folder inside the src folder, and call it lib. Inside lib, create and

├── rusty snake
│    ├── src
│    │    ├── lib
│    │    │    ├──
│    │    │    └──
│    │    │
│    │    └──
│    │
│    ├── Cargo.lock
│    └── Cargo.toml
└── ...

Move all functions you wrote to In order for this to work, all dependencies that these functions need, also need to be declared in If they are not used in, you can delete them there.


Dependencies for the moved functions have to be moved to too.

Making Functions and structs Public

In order for a function to be accessible in, it needs to be marked with pub.

Accessing the Modules in

Before fn main() add the following line:

fn main() {
pub mod lib;

Functions now have to be called in the namespace of the module:

fn main() {
let (canvas, mut events) = lib::init(canvas_width, canvas_height);