Sharing one library crate between two binary crates

⚓ Rust    📅 2026-02-05    👤 surdeus    👁️ 8      

surdeus

In my project, I have two binary crates. One provides the back-end using actix_web, the other one is meant (it's not even nearly finished) to provide the front-end using Dioxus. They communicate over a HTTP API with JSON.
Effectively, I serialize the back-end data into JSON using serde_json and a struct into JSON and the deserialize the JSON into exactly the same struct as the backend used originally. Now, I think it would just be a waste of lines of code to copy the structs from the back-end code to the front-end code. I also imagine sharing the exact same structs could bring more benefits like not accidentally mixing up names of structs, better auto-completion and better type safety.
To achieve this, I considered making a library crate that the two binary crates can both access that will contain the structs.
Now, I do not know how I could share a library crate between two binary crates without having to upload it to crates.io or copy it into both other crates. The binary crates are both in separate directories in one common directory and I considered creating the library crate in the same common directory.
It would be great if somebody could help me out with this :slight_smile:

3 posts - 3 participants

Read full topic

🏷️ Rust_feed