Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

use 선언

use 선언을 사용하여 전체 경로를 새로운 이름에 바인딩하여 더 쉽게 접근할 수 있습니다. 다음과 같이 자주 사용됩니다:

use crate::deeply::nested::{
    my_first_function,
    my_second_function,
    AndATraitType
};

fn main() {
    my_first_function();
}

as 키워드를 사용하여 임포트(imports)를 다른 이름에 바인딩할 수 있습니다:

// `deeply::nested::function` 경로를 `other_function`에 바인딩합니다.
use deeply::nested::function as other_function;

fn function() {
    println!("`function()` 호출됨");
}

mod deeply {
    pub mod nested {
        pub fn function() {
            println!("`deeply::nested::function()` 호출됨");
        }
    }
}

fn main() {
    // `deeply::nested::function`에 더 쉽게 접근
    other_function();

    println!("블록 진입");
    {
        // 이는 `use deeply::nested::function as function`과 동일합니다.
// 이 `function()`은 외부의 것을 섀도잉합니다.
        use crate::deeply::nested::function;

        // `use` 바인딩은 지역 스코프를 가집니다. 이 경우
// `function()`의 섀도잉은 이 블록 내에서만 유효합니다.
        function();

        println!("블록 나감");
    }

    function();
}