Rust app, browser as gui, 3 vs 1 crate?


#1

Here’s the situation:

  1. I’m writing an app in Rust.

  2. For the front end, I’m using web browser (talking to backend via websockets).

  3. The current pattern is to have three crates: foobar_client, foobar_server, foobar_shared.

  4. I am wondering if it makes more sense to only have one crate, and use conditional compilation.

=====

Argument for three crates: separation of concerns.

Argument for one crate: the three causes unnecessary split. It’s really a single app at heart.

For those who have dealt with this issue, what did you end up going with?


#2

Consider using 3 separate crates in a single git repo using cargo workspaces. This will allow you to implement the separation of concerns, while mitigating the downsides of maintaining semver compatibility across 3 tightly-coupled crates.


#3

Take a look at piston, they have a piston repo, but it really is just three rust projects in different folders. If it were me, I’d use the same concept (Well, I’d actually never try to take on a project of that size), because it’s so easy to depend on the other crates.