error: cannot find derive macro `JsonSchema` in this scope
--> src/lib.rs:5:10
|
5 | #[derive(JsonSchema)]
| ^^^^^^^^^^
|
note: `JsonSchema` is a trait, not a derive macro
--> /playground/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/schemars-1.2.3/src/lib.rs:136:1
|
136 | pub trait JsonSchema {
| ^^^^^^^^^^^^^^^^^^^^
= help: consider implementing `JsonSchema` for your type manually
error: could not compile `playground` (lib) due to 1 previous error
This is because the derive feature is missing. Are the Playground's default dependencies preconfigured? If so, it would be worth looking into which features are most commonly used.
The Rust Playground supports preconfigured dependencies, including feature selection. However, I noticed that schemars 1.2.3 enables the derive feature by default, so this error may indicate that default features are being disabled in the Playground's dependency configuration.
It would also be worth checking how the Playground configures dependency features and ensuring that commonly used features, especially default features, are enabled where appropriate.
For example, explicitly enabling the feature should resolve this:
[dependencies]
schemars = { version = "1.2.3", features = ["derive"] }
[dependencies.schemars]
package = "schemars"
version = "=1.2.3"
default-features = false
In other words, you get 1.2.3 with default features turned off, which will be why there's no derive feature enabled.
The Rust Playground Crates Policy says that the crate author can add metadata to schemars's Cargo.toml, which will tell the playground which features should be available - I'd suggest asking the schemars maintainer to add that metadata, so that future crate updates for the Playground will pick up the suggested feature flags.
It turns out that tinyvec itself sets the playground metadata and uses it to enable the schemars feature:
I don't know that I agree with this decision from tinyvec's maintainers. Roughly speaking, I look at the metadata as saying "if my crate shows up on the playground, it must have these features enabled in order to be useful to the vast majority of people using the crate". The schemars and borsh features both feel like they are niche extensions that don't meet that bar.
Every feature enabled has the potential to increase the number of crates built (over 500 at the moment), and those take time and space. Hypothetically, schemars (with 730M downloads, roughly #225 most-downloaded) is taking up the slot that the 101st most-downloaded crate (uuid, with 1B downloads) could be using. It doesn't literally work out like that in this case, as I know that uuid is pulled in otherwise, but I hope the example stands.