Shared lib between two example binaries

I'm creating a project (a lib) for communicating over a bus-like system. In the project I have two example binaries, a producer and a consumer.

examples
├── consumer
│   └── main.rs
├── common
│   └── lib.rs
└── producer
    └── main.rs

Is there any way I can make the "common" lib a library that is shared between consumer and producer?

To be clear, "common" is just a lib for the examples.

You can't make it an actual library (Cargo will only build one library crate per package), but you could import it as a module into each binary. In both consumer/main.rs and producer/main.rs, add this:

#[path = "../common/lib.rs"]
mod common;

The main downside compared to a "real" library is that the code in common will be compiled twice (once for each binary).

Hey,

that will work perfectly for me!

Thank you!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.