1

My Rust project structure inside src folder:

|main.rs
|routes folder: 
   |-mod.rs
   |-route_func.rs
|blockchain folder:
   |simple_func.rs

I got this error message: function exists but is inaccessible

How can I use the simple_func.rs functions inside the route_func.rs ?

It seems I need to construct a module tree...

Russo
  • 2,186
  • 2
  • 26
  • 42
  • 1
    Impossible to answer without seeing the actual code. Perhaps you forgot to declare a module public or something similar? – chepner Feb 10 '23 at 14:26

1 Answers1

3

Declare the new module in your main.rs file:

pub mod blockchain;

Declare your new module content inside the blockchain/mod.rs:

pub mod simple_func;

Declare the target function inside simple_func.rs

pub async fn target_func() -> {}

Import the target_func in the route_func.rs:

use crate::blockchain::simple_func::*;

Remember to add pub in all declarations and functions!

Russo
  • 2,186
  • 2
  • 26
  • 42