9.3 The use declaration
use 선언은 전체 경로를 새 이름으로 사용할 수 있도록 바인딩해줘 쉽게 사용할 수 있다.
The use declaration can be used to bind a full path to a new name, for easier
access.
// `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::function` 보다 쉽게 접근.
other_function();
println!("Entering block");
{
// 이는 `use depply::nested::function as function`과 동일.
// 이 `function()`는 외부 것을 은닉한다.
use deeply::nested::function;
function();
// `use` 바인딩은 지역 범위를 갖는다. 여기서
// `function()`의 은닉은 이 블럭에서만 유효하다.
println!("Leaving block");
}
function();
}