如何从 Rust 中的模块导入单个函数?

Edg*_*gón 2 import module rust unused-variables

I'm fairly new to Rust and coming from Python there are some things that are done very differently. In Python, one can import a single function from a .py file by typing from foo import bar, but I still haven't found any equivalent in Rust.

I have the following files:

.
??? main.rs
??? module.rs
Run Code Online (Sandbox Code Playgroud)

With the following contents:

main.rs

mod module;

fn main() {
    module::hello();
}
Run Code Online (Sandbox Code Playgroud)

module.rs

pub fn hello() {
    println!("Hello");
}

pub fn bye() {
    println!("Bye");
}
Run Code Online (Sandbox Code Playgroud)

How do I create my module or type my imports so that I don't get the following warning:

mod module;

fn main() {
    module::hello();
}
Run Code Online (Sandbox Code Playgroud)

She*_*ter 5

导入模块、类型、函数、特征没有什么实质性的不同:

use path::to::function;
Run Code Online (Sandbox Code Playgroud)

例如:

mod foo {
    pub fn bar() {}
}

use foo::bar;

fn main() {
    bar();
}
Run Code Online (Sandbox Code Playgroud)