I have the following code in main.rs
fn util_function() -> Result<String, std::io::Error> {
Ok(String::from("OK"))
}
fn main() {
let a = util_function().unwrap();
}
I split main.rs
into two files:
// util.rs
fn util_function() -> Result<String, std::io::Error> {
Ok(String::from("OK"))
}
and
// main.rs
mod util;
fn main() {
let a = util::util_function().unwrap();
}
The problem that util.rs
has a compilation error:
pub fn util_function(mut stream: &TcpStream) -> Result<String, std::io::Error> {
| ^^^ Use of undeclared type or module `std`
So why should I add using std;
to the utils.rs
while it is not necessary in main.rs
?