We are considering Rust for a cross-platform project. It would be deployed like so:
- Database Layer (diesel)
- Backend API (ie: actix/juniper)
- Embeded Device (ie: ESP32) which would call the API
- Web & Mobile Applications (ie: dioxus)
Many of these frameworks seem nice and clean on their own:
- Make your struct
- Annotate it with derive macros
- Use it.
So, I make a struct for some entity - say, Person. All platforms need to know about Person. 95% of the fields are the same type, same visibility, same business logic. Then I annotate it with diesel, juniper, and dioxus derive statements. Won't that end up including say, diesel code into my embedded project? (which would be bad idea, and break our architectural idea here...)
What are folks doing for project organization on such a project?
- Single crate, single repo and don't worry about including diesel on the embedded project? (will the compiler be smart enough NOT to include diesel in the embedded output?)
- Multiple related crates in a workspace? if so - how are you organizing things such that you don't have to duplicate structs vs. include functionality where you don't need it. (so, how do we make sure we don't end up with say, diesel being a dependency for the embedded project?)
It would seem to me that if these frameworks use traits, it might be possible to have the generic structs in 1 crate, and then api crate, web/mobile crate, and embedded create could refer to, and extend them- adding traits as needed for their part of the project.
But if the frameworks use derive macros, how would i do this? Is the answer really to have the same structs all over (ApiPerson, DatabasePerson, WebPerson, EmbededPerson), and write a bunch of boilerplate adapter code between the layers? (well, duplicate objects, each of which can serde with json from the api layer)
Are we worrying about a non-issue here? Are we missing some key concept of the "rust way" to solve for clean project dependencies?
For clarity - a diagram... is there nothing to worry about on right-hand option? or a 3rd clean way to do this we're missing?
Thank you much for your advice