DEV Community

loading...

Discussion on: Why the Rust module system might be hard to understand

Collapse
alexxbb profile image
alexxbb

I don't know what is so hard in Rust module system? Module is a single rust file, it can only exist within Crate. The latter is basically what other languages call a library, and is what you add to your project. You don't share Rust modules, you share crates. That's it

Collapse
u007d profile image
Brad Gibson • Edited

Unfortunately it's not quite so straightforward:

Take for example a file foo.rs:

// filename: foo.rs
pub fn foo() {}

mod bar {
    pub fn bar() {}
}
Enter fullscreen mode Exit fullscreen mode

Above, you have foo.rs defining a foo module AND a bar module--all within 1 file. The author is right, it is confusing for people to pick up.

I was hoping the author would provide a clarifying succinct definition I could use to help new people "get" Rust's module system...

Collapse
dotxlem profile image
Dan Author • Edited

I was hoping the author would provide a clarifying succinct definition I could use to help new people "get" Rust's module system...

I didn't try to provide an explanation because I wasn't sure I could do any better than what I've seen out there already. If there's interest though, maybe it'd be worth giving it a shot!

I'll ping here if I post something :)

Forem Open with the Forem app