'Rust - How can I call functions from my src folder to code in my examples folder?
If I have this function in src/test.rs
pub fn print_something(){
println!("Something");
}
how can I call it in the example/test.rs ?
I've tried with extern crate, mod, use but none of these worked.
Solution 1:[1]
First, you have to declare the test module in src/lib.rs:
pub mod test;
Then, inside examples/test.rs, just use it as a library:
crate_name::test::print_something(); // Replace `crate_name` by the crate name
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Chayim Friedman |
