How should I structure a web project that has a server, client and shared data between them? [closed]

冷暖自知 提交于 2020-07-10 10:24:21

问题


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:

  1. Is there a way to share dependencies in one place? Rust workspace doesn't seem to implement this yet.

  2. 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).

  3. 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.

  4. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!