//! Types for the `before_serve` configuration and `exec_aliases` table. //! //! Lives outside `config.rs` so the latter stays under the 500-line limit //! the project enforces (see AGENTS.md). use serde::Deserialize; /// Behaviour on a non-zero exit code for a [`PreServeCommand`]. #[derive(Clone, Copy, Debug, PartialEq, Eq, Default, Deserialize)] #[serde(rename_all = "lowercase")] pub enum OnFailure { #[default] Abort, Warn, Continue, } /// One entry in a `before_serve` block. #[derive(Clone, Debug, Deserialize)] #[serde(untagged)] pub enum PreServeCommand { Bare(String), Configured { command: String, #[serde(default)] on_failure: OnFailure, }, } impl PreServeCommand { pub fn command(&self) -> &str { match self { PreServeCommand::Bare(c) => c, PreServeCommand::Configured { command, .. } => command, } } pub fn on_failure(&self) -> OnFailure { match self { PreServeCommand::Bare(_) => OnFailure::default(), PreServeCommand::Configured { on_failure, .. } => *on_failure, } } } #[derive(Clone, Debug, Default, Deserialize)] pub struct BeforeServeTable { #[serde(default)] pub commands: Vec, } #[derive(Clone, Debug, Default, Deserialize)] pub struct ModsTable { #[serde(default)] pub commands: Vec, } /// Distributed execution backend — `mp`, `ray`, or absent (single-node). /// Defaults to [`None_`] when not specified in the recipe. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Deserialize)] #[serde(rename_all = "lowercase")] pub enum DistributedBackend { Mp, Ray, #[default] None_, } impl std::fmt::Display for DistributedBackend { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { DistributedBackend::Mp => write!(f, "mp"), DistributedBackend::Ray => write!(f, "ray"), DistributedBackend::None_ => write!(f, "none"), } } }