Skip to main content

boxferry_compose/
deferred.rs

1//! Explicit Compose-to-Quadlet execution-environment policy.
2use boxferry_model::{Identifier, ModelError, ServiceExecutionEnvironment, Sourced};
3use std::collections::BTreeMap;
4
5/// Per-service explicit deferral allowlists and service execution providers.
6///
7/// This policy never evaluates variables, reads provider files, or accesses the process environment.
8/// Import un-interpolated native merged input. Every plan must belong to an active service and all
9/// declared references must be used. Provider values do not imply container-variable forwarding.
10#[derive(Clone, Debug, Default, Eq, PartialEq)]
11pub struct QuadletDeferredOptions {
12    services: BTreeMap<Identifier, Sourced<ServiceExecutionEnvironment>>,
13}
14impl QuadletDeferredOptions {
15    /// Creates an empty opt-in policy.
16    #[must_use]
17    pub const fn new() -> Self {
18        Self {
19            services: BTreeMap::new(),
20        }
21    }
22    /// Adds an explicit service plan without replacing a previous declaration.
23    /// # Errors
24    /// Returns a value-free error for duplicate service plans.
25    pub fn add_service(
26        &mut self,
27        name: Identifier,
28        plan: Sourced<ServiceExecutionEnvironment>,
29    ) -> Result<(), ModelError> {
30        if self.services.contains_key(&name) {
31            return Err(ModelError::InvalidDeferred("duplicate service execution plan"));
32        }
33        self.services.insert(name, plan);
34        Ok(())
35    }
36    /// Returns plans by service identity.
37    #[must_use]
38    pub const fn services(&self) -> &BTreeMap<Identifier, Sourced<ServiceExecutionEnvironment>> {
39        &self.services
40    }
41    /// Returns whether the explicit mode has any plans.
42    #[must_use]
43    pub fn is_empty(&self) -> bool {
44        self.services.is_empty()
45    }
46}