How to use functions from different folders under crate root?

Under my src folder, I have two subdirectories called renderhd, and render4k. I have a (obviously!) from which I want to call render4k/

How can this be achieved without moving everything into the src root?

In your src/, declare modules for each of your subdirectories:

mod renderhd;
mod render4k;

Then Rust will look for either src/ or src/render4k/ (and similar for renderhd); I prefer using src/ In that file, declare modules for the files in your subdirectories, so src/ will declare modules for each of the files in src/render4k/. These modules need to be public, like so:

pub mod lowthreaded;

If src/render4k/ contains a public function like:

pub fn foo() {

Then in src/, you can call it with:

fn main() {

Chapter 7 of the book has more info on all of this :slight_smile:


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.