Is it possible to specify a dependency just for the main crate?

I want a dependency to be only used on the main crate, is it possible?

I don't think so.
A solution would be to write the main crate separate from the library crate (ie, under a different Cargo.toml file). Then add the library crate as a dependency (probably a path dependency) to the main crate. Finally, you can add your special dependency to the main crate, and it won't affect the library crate.

1 Like

No, if you have two primary and secondary crate, you use tokio in the primary crate, but you want the secondary crate to use tokio, you have to add tokio dependency to the secondary crate. In the same project, your secondary crate can be added to the primary crate through path specification. Cargo is not like Maven and Gradle

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.