mind-body: need() as a fn so the borrowed value outlives the closure

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-09 16:01:14 +02:00
commit 76367e888a

View file

@ -70,7 +70,6 @@ fn parse_dial(flags: &[&str], now: DateTime<Utc>, set_by: &str) -> Result<BurnRa
bail!("{flag} given twice");
}
}
let need = |value: Option<&str>, name: &str| value.ok_or_else(|| anyhow!("{name} is required"));
Ok(BurnRate {
heat: Decimal::from_str(need(heat, "--heat")?).context("--heat is not a decimal")?,
base_cooldown_s: need(cooldown, "--base-cooldown-s")?
@ -82,6 +81,10 @@ fn parse_dial(flags: &[&str], now: DateTime<Utc>, set_by: &str) -> Result<BurnRa
})
}
fn need<'a>(value: Option<&'a str>, name: &str) -> Result<&'a str> {
value.ok_or_else(|| anyhow!("{name} is required"))
}
fn show(path: &Path, instance: &Slug, out: &mut impl Write) -> Result<()> {
let source = FileSource::new(path);
writeln!(out, "instance: {}", instance.0)?;