Cargo reads and writes user and machine facing data formats, like
Cargo.toml, read and written on cargo packageCargo.lock, read and written.cargo/config.toml, read-onlycargo metadata outputcargo build --message-format outputGenerally,
#[serde(rename_all = "kebab-case")] should be applied defensively#[serde(skip_serializing_if = "Default::default")] should be applied liberally#[serde(deny_unknown_fields)] should not be used to allow evolution of formats, including feature gatingWhen changing a schema for data that is read, some options include:
edition requires a minimum package.rust-version, if present)edition field or package.resolver which has an edition fallback)Note: some formats that are read are also written back out (e.g. cargo package generating a Cargo.toml file) and those strategies need to be considered as well.
When changing a schema for data that is written, some options include:
enum variant)cargo metadata --format-version, edition in cargo script)package.edition in Cargo.toml)package.rust-version, or a command-line flag like --format-version)Note: While serde makes it easy to support data formats that add new fields, new data types or supported values for a field are more difficult to future-proof against.