Because Cargo uses lib.rs
as entry point by default and lib.rs
doesn’t tell Rust about any other file. You need to use modules for that:
mod file;
use file::check;
fn it_works() {
check();
}
The mod file;
line tells Rust there is a module file.rs
or file/mod.rs
and the use file::check;
line tells rust to import the check function from the “file” module so that you don’t have to call it using full module “path” file::check()
You can read more about modules in the book
Edit: Doing some checks I noticed I forgot to talk about visibility. For your check
function to be callable from another module you need to annotate it with the pub
keyword, essentially saying this item is accessible from outside the module.