How to specify doc-test only dependencies in Cargo.toml?

I have a crate called serde-aux where I provide some useful(-ish) ser/deserialize implementations either for structs or fields. I noticed that my crate has the serde_json specified as a runtime dependency but the crate itself doesn't use those at all, the serde_json crate is only used within the doc tests to show people how the deserializition should work with different input, e.g. what to expect and when. I was expecting to have something like:

serde_json = "1"

You should be using [dev-dependencies] for this. It's not possible to specify dependencies for doc tests, but not other kinds of tests.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.