Just like you’re able to use the same copy of a library from cargo.toml in your canisters, you are also able to reuse your own libraries.
I don’t know what is your project structure, but for a multi-canister setup I would recommend putting each canister into a separate crate. So you would have something like this:
my_workspace/
canister_a/
src/
cargo.toml
canister_b/
src/
cargo.toml
canister_c/
src/
cargo.toml
# this one is special
shared_lib/
src/
types.rs
cargo.toml
If you do it like that, then you can simply put
shared_lib: { path: "../shared_lib" }
into cargo.toml of each of your canister.
Doing like this allows you to easily decouple canisters from each other later when your project scales.
Once you have added the reference shared = { path = "../shared" } in a canister, how do you use your types modules?
Tried use crate::shared::types::{Args}; but I am missing something…
shared/
src/
types.rs
cargo.toml
canister_a/
src/
lib.rs <-- here I tried to use `use crate::shared::types::{Args};`
cargo.toml <-- here I added the path
What IDE are you using? On VSCode it should work to simply write let something:Args... And then it will highlight Args, and if you ctrl+. on that highlight it would offer to import it for you, and should be pretty good at it since you defined it in Cargo.toml.
I remember CLion having something similar, tho’ I only used it for a brief period and can’t remember the shortcut from memory.