3 ms·
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
by 8K832d7tNmiQ 4y ago
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.
- deleted 4y ago[deleted]
- bobbylarrybobby 4y agoRust 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.
- duped 4y agoFolder 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.