Modules

impl๋ธ”๋ก์€ ๋„ค์ž„์ŠคํŽ˜์ด์Šคํ•จ์ˆ˜๋ฅผ ํƒ€์ž…์œผ๋กœ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. mod ์—ญ์‹œ ๋„ค์ž„์ŠคํŽ˜์ด์Šค ํƒ€์ž…๊ณผ ํ•จ์ˆ˜๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค:

We have seen how impl blocks let us namespace functions to a type. Similarly, mod lets us namespace types and functions:

mod foo {
    pub fn do_something() {
        println!("In the foo module");
    }
}

mod bar {
    pub fn do_something() {
        println!("In the bar module");
    }
}

fn main() {
    foo::do_something();
    bar::do_something();
}