I'm building an app that hooks some Windows events.
The hook code must be in a DLL for that to work. I set [lib]
with crate-type = ["cdylib"]
in Cargo.toml
and use it in main.rs
.
│ Cargo.toml
│
└───src
lib.rs
main.rs
It works.
I want to add a second binary, so use this structure:
└───src
│ lib.rs
│
└───bin
bin1.rs
bin2.rs
It works.
bin1.rs
and bin2.rs
have some duplicated code that I want to moved to a new app.rs
module, so I try this:
└───src
│ lib.rs
│
└───bin
app.rs
bin1.rs
bin2.rs
This causes an error 'main' function not found in crate 'app'
. That is because all files in bin
are expected to be built as binaries.
I move app.rs
out of bin
and try a different structure:
└───src
│ lib.rs
│ app.rs
│
└───bin
bin1.rs
bin2.rs
With that structure, bin1.rs
and bin2.rs
can't access app.rs
.
Usually the shared code would go in lib.rs
, but that is my DLL.
How should this situation be handled?