Skip to main content

lightshuttle_export/
emit.rs

1//! The emitter contract: turn an [`ExportModel`] into target files.
2
3use crate::error::Result;
4use crate::model::{ExportArtifacts, ExportModel, Target};
5
6/// Transpiles an [`ExportModel`] into the files of a single deployment target.
7///
8/// Implementations live in their own modules: [`crate::ComposeEmitter`],
9/// [`crate::KubernetesEmitter`], and [`crate::HelmEmitter`].
10///
11/// # Determinism requirement
12///
13/// Emitters must produce deterministic output. Container environment maps are
14/// unordered, so any map-derived output must be sorted by key before it is
15/// written - otherwise golden-file tests become flaky.
16///
17/// # Example
18///
19/// ```rust
20/// use lightshuttle_export::{Emitter, ComposeEmitter, Target};
21///
22/// let emitter = ComposeEmitter;
23/// assert_eq!(emitter.target(), Target::Compose);
24/// ```
25pub trait Emitter {
26    /// Returns the [`Target`] that this emitter produces.
27    fn target(&self) -> Target;
28
29    /// Transpiles `model` into a set of named files for the emitter's target.
30    ///
31    /// # Errors
32    ///
33    /// Returns [`crate::ExportError::Unsupported`] when a resource in `model`
34    /// cannot be represented for this target (for example, a locally built
35    /// image referenced by a Kubernetes manifest).
36    fn emit(&self, model: &ExportModel) -> Result<ExportArtifacts>;
37}