|
|
|
|
|
by pornel
2046 days ago
|
|
Files aren't modules. Modules are defined in the source code the same way as any named "item" in the language, like structs and functions. The only difference is that content of `{}` following the definition of a module can be read from another file. You can have a module without a file: mod foo {
fn function_in_foo() {}
mod bar {
// this is crate::foo::bar module!
}
}
but if you omit {}: mod foo;
Rust will look for `foo.rs` to drop its content where the {} should have been. But namespacing is governed by `mod` declarations alone, not files. |
|
Every file is a module, but not every module is a file.
If `mod foo;` is the only way to make sure a file's code gets compiled, then at some point every file gets its own module, right?