问题
I want to understand how to structure web-project that has server, client and shared between them data (folder/lib or whatever).
I will use actix-web for the server and yew for the client.
The structure should be something like
├── server
│ ├── Cargo.toml
│ └── src
│ └── main.rs
├── client
│ ├── Cargo.toml
│ └── src
│ └── main.rs
│── shared
│ ├── Cargo.toml
│ └── src
│ └── lib.rs
Server and client Cargo.toml
[dependencies]
shared = { path = "../shared" }
Shared lib.rs
pub fn todo() -> i32 {
2
}
Server and client main.rs
use shared::todo;
fn main() {
println!("Hello, world!, {}", todo());
}
Server and client build separately for development using cargo watch -x run -w ../shared
All seems to work fine, but:
Is there a way to share dependencies in one place? Rust workspace doesn't seem to implement this yet.
It's seems that when I change something in lib it gets compiled two times because Cargo watch is running in two consoles (client and server).
If I want to compile the server with one argument for shared data and the client with another, I assume it will break the code because the client or server will use the shared lib that was compiled last.
I'm not sure that this way is the right approach.
来源:https://stackoverflow.com/questions/62804503/how-should-i-structure-a-web-project-that-has-a-server-client-and-shared-data-b