News for hackers. Stuff that matters.
Re:Learning Rust – Day 4 – Understanding Modules by 8K832d7tNmiQ on Thursday May 12, 2022 @01:34PM (#31357308)
importing a module is the most fustrating part of writing rust code next to writing a multiple-spawn tasks.

Can someone help me how to import a module in lib/m.rs from lib.rs ? I've never seen someone asked about it.

Re:Learning Rust – Day 4 – Understanding Modules by duped on Thursday May 12, 2022 @04:48PM (#31359972)
Folder structure

    src/lib.rs
        lib/
            mod.rs
            m.rs
In lib.rs

    use lib::m;
In lib/mod.rs

    pub mod m;
You need the mod.rs file in subdirectories.
Re:Learning Rust – Day 4 – Understanding Modules by bobbylarrybobby on Thursday May 12, 2022 @02:40PM (#31358374)
Rust has two distinct semantics surrounding how items can be "in scope".

First, the `mod` keyword takes a module that the current file/scope can see and makes it available within that file/scope as if it had been defined there. This is necessary to make the module's items accessible, i.e., specifiable by their path within the module, in the current file/scope.

Then the `use` keyword takes an already-accessible member of a named scope -- a module, a type, etc -- and makes it usable by name (i.e., without scoping on each use) in the current scope.