Skip to main content

pacenotes_server/store/
sidecar.rs

1/// The optional `<name>.toml` a publisher writes next to a zip.
2///
3/// Unknown keys are an error, so a sidecar still carrying a retired
4/// positional key (`category`, `tree_path`, `game`) fails the run.
5#[derive(serde::Deserialize, Default)]
6#[serde(deny_unknown_fields)]
7pub struct Sidecar {
8    pub version: Option<String>,
9    pub display_name: Option<String>,
10    pub description: Option<String>,
11    pub exclusive_group: Option<String>,
12    pub requires: Option<Vec<String>>,
13}
14
15/// A missing sidecar is the normal case and reads as an empty one.
16pub fn read_sidecar(path: &std::path::Path) -> anyhow::Result<Sidecar> {
17    let text = match std::fs::read_to_string(path) {
18        Ok(text) => text,
19        Err(e) if e.kind() == std::io::ErrorKind::NotFound => return Ok(Sidecar::default()),
20        Err(e) => anyhow::bail!("reading {}: {e}", path.display()),
21    };
22    parse_sidecar(&text)
23}
24
25pub fn parse_sidecar(text: &str) -> anyhow::Result<Sidecar> {
26    toml::from_str(text).map_err(|e| anyhow::anyhow!("{e}"))
27}