About Rust Playground's dependencies's default features

While using the Rust Playground, I noticed that a dependency was missing a feature I needed:

extern crate schemars; // 1.2.3

use schemars::JsonSchema;

#[derive(JsonSchema)]
pub struct MyStruct;
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"] }

The Rust Playground is an open source project, and you can see the Cargo.toml that defines which crates are available by default online. At the time I write this, it contains:

[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.

And that is because schemars is pulled into the playground due to its use in tinyvec, which turns off the default features:

What confused me is why the schemars feature is enabled at all, as the crate that depends on tinyvec doesn't enable it.

full dependency chain

postgres v0.19.14
tokio-postgres v0.7.19
postgres-types v0.2.15
postgres-protocol v0.6.13
stringprep v0.1.5
unicode-normalization v0.1.26
tinyvec v1.13.3
schemars v1.2.3

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.