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:
mod module;
fn main() {
module::hello();
}
Run Code Online (Sandbox Code Playgroud)
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)
导入模块、类型、函数、特征没有什么实质性的不同:
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)
| 归档时间: |
|
| 查看次数: |
897 次 |
| 最近记录: |