Kofthefens
Kofthefens

Reputation: 259

Split rust library functions across multiple files

I am using rust to provide faster functions to a webapp through WASM. This involves creating a large number of helper functions, and while I can put them all in a single file (lib.rs), it would quickly get cluttered. To that end, I would like to have the following file hierarchy:

|-- src
|   |-- lib.rs
|   |-- helper1.rs
|   |-- helper2.rs

Where a file like helper1.rs might look like:

use wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub fn helper1()  {
    // Do something useful
}

Upvotes: 0

Views: 185

Answers (1)

Kofthefens
Kofthefens

Reputation: 259

In lib.rs, include:

mod helper1;
mod helper2;

This will make the two helper files get linked in.

Upvotes: 3

Related Questions