热门

最新

红包

立Flag

投票

同城

我的

发布
ilypl
软硬兼吃曹达华
4 年前
trueilypl

// 将 `deeply::nested::function` 路径绑定到 `other_function`。
use deeply::nested::function as other_function;

fn function() {
println!("called `function()`");
}

mod deeply {
pub mod nested {
pub fn function() {
println!("called `deeply::nested::function()`")
}
}
}

fn main() {
// 更容易访问 `deeply::nested::funcion`
other_function();

println!("Entering block");
{
// 这和 `use deeply::nested::function as function` 等价。
// 此 `function()` 将遮蔽外部的同名函数。
use deeply::nested::function;
function();

// `use` 绑定拥有局部作用域。在这个例子中,`function()`
// 的遮蔽只存在这个代码块中。
println!("Leaving block");
}

function();
}

CSDN App 扫码分享
分享
评论
1
打赏
  • 复制链接
  • 举报
下一条:
use 声明可以将一个完整的路径绑定到一个新的名字,从而更容易访问。
立即登录