News for hackers. Stuff that matters.
Re:Rust Dependencies Scare Me by xlii on Friday May 09, 2025 @05:15PM (#43940937)
> Go and Rust, for example, encourage everything for a single package/mod to go in the same file.

Clarification: Go allows for a very simple multi-file. It’s one feature I really like, because it allows splitting otherwise coherent module into logical parts.

Re:Rust Dependencies Scare Me by dcow on Friday May 09, 2025 @05:24PM (#43941007)
Further: I’ve never seen rust encourage anything of the sort. Module directory with a mod.rs and any number of files works just fine.
Re:Rust Dependencies Scare Me by kion on Friday May 09, 2025 @05:27PM (#43941047)
I probably mischaracterized this as its been a while since I did more than trivial Rust. AFAIK its not possible to depend on only a part of a module in Rust though right? (At least without an external build system)

For example, you can't split up a module into foo.rs containing `Foo` and bar.rs containing `Bar`, both in module 'mymod' in such a way that you can `use mymod::Bar and foo.rs is never built/linked.

My point is the granularity of the package/mod encourages course-grained deps, which I argue is a problem.

Re:Rust Dependencies Scare Me by dathinab on Friday May 09, 2025 @06:28PM (#43941523)
> not possible to depend on only a part of a module in Rust though right

yesn't, you can use feature flags similar to `#if` in C

but it's also not really a needed feature as dead code elimination will prune out all code functions, types, etc. you don't use. Non of it will end up in the produced binary.

Re:Rust Dependencies Scare Me by eddd-ddde on Friday May 09, 2025 @05:45PM (#43941191)
You'd use feature flags to enable certain parts of the library.
Re:Rust Dependencies Scare Me by tialaramex on Friday May 09, 2025 @06:07PM (#43941365)
Yeah, likewise Rust is completely fine after you say `mod foo` and have a file named foo.rs, if you also make a foo/ directory and put foo/whatever.rs and foo/something_else.rs that those are all part of the foo module.

Historically Rust wanted that foo.rs to be renamed foo/mod.rs but that's no longer idiomatic although of course it still works if you do that.

Re:Rust Dependencies Scare Me by dathinab on Friday May 09, 2025 @06:27PM (#43941505)
to extend on this:

in rust crates are semantically one compilation unit (where in C oversimplified it's a .h/.c pair, and practically rustc will try to split it in some more units to speed up build time).

the reason I'm pointing this out is because many sources of "splitting a module across files" come from situations where 1 file is one compilation unit so you needed to have a way to split it (for organization) without splitting it (for compilation) in some sitation

Re:Rust Dependencies Scare Me by mseepgood on Saturday May 10, 2025 @04:40AM (#43944142)
Not just multiple files, but multiple directories. One versioned dependency (module) usually consists of dozens of directories (packages) and dozens to hundreds of files. Only newcomers from other languages create too many go.mod files when they shouldn't.