Are we fine with types, structs and model crates or are they code smell?
I've studied some Rust repositories that use workspaces. And almost all of them have a crate or a module to define structs.
- Rust compiler itself
- https://github.com/Discord-TTS/Bot/blob/master/tts_core/src/structs.rs
- https://github.com/mullvad/mullvadvpn-app/tree/main/mullvad-types
I assume they revert back to this to avoid cyclic dependencies. There is really no way around it afaik. Coming from Go, which is really opinionated about code style the general recommendation is against packages like common or shared or types. But then again, Go also doesn't allow cyclic deps.
I have structs like Channel in lib.rs:
#[derive(Debug)]
pub struct Channel {
pub id: i64,
// ...
}
I also have a module to query from my database: db.rs. It returns structs defined in lib.rs.
Now, in lib.rs I call functions from db.rs. But in db.rs I use structs from lib.rs. This feels cyclic but isn't because one crate is one translation unit.
If I want to separate into crates and use workspaces I'd have
project(types defined here)project-dbproject-event
So I'm forced to outsource type defs:
projectproject-types(orbot-model)project-dbproject-event
Are we fine with this? Having a types or structs or model create. The use of common, shared is code smell in my opinion.