Skip to main content

Emitter

Trait Emitter 

Source
pub trait Emitter: Send + Sync {
    // Required methods
    fn emit_thin(
        &self,
        ir: &IntermediateRepresentation,
    ) -> EmitterResult<String>;
    fn emit_expanded(
        &self,
        ir: &IntermediateRepresentation,
    ) -> EmitterResult<String>;
    fn format_name(&self) -> &'static str;
    fn file_extension(&self) -> &'static str;

    // Provided methods
    fn emit(&self, ir: &IntermediateRepresentation) -> EmitterResult<String> { ... }
    fn description(&self) -> &'static str { ... }
    fn validate(&self, ir: &IntermediateRepresentation) -> EmitterResult<()> { ... }
}
Expand description

Trait for CI configuration emitters

Implementations transform the IR into orchestrator-specific configurations. Each emitter is responsible for mapping IR concepts to the target format.

§Pipeline Modes

Emitters must implement both emit_thin and emit_expanded methods:

  • emit_thin: Single-job workflow with cuenv orchestration
  • emit_expanded: Multi-job workflow with orchestrator dependencies

The default emit method dispatches based on ir.pipeline.mode.

§Example

use cuenv_ci::emitter::{Emitter, EmitterResult};
use cuenv_ci::ir::IntermediateRepresentation;

struct MyEmitter;

impl Emitter for MyEmitter {
    fn emit_thin(&self, ir: &IntermediateRepresentation) -> EmitterResult<String> {
        // Generate single-job workflow
        Ok("# Thin mode config".to_string())
    }

    fn emit_expanded(&self, ir: &IntermediateRepresentation) -> EmitterResult<String> {
        // Generate multi-job workflow
        Ok("# Expanded mode config".to_string())
    }

    fn format_name(&self) -> &'static str {
        "my-ci"
    }

    fn file_extension(&self) -> &'static str {
        "yml"
    }
}

Required Methods§

Source

fn emit_thin(&self, ir: &IntermediateRepresentation) -> EmitterResult<String>

Emit a thin mode CI configuration.

Thin mode generates a single-job workflow that:

  1. Runs bootstrap phase steps (e.g., install Nix)
  2. Runs setup phase steps (e.g., build cuenv)
  3. Executes cuenv ci --pipeline <name> for orchestration
  4. Runs success/failure phase steps with conditions
§Arguments
  • ir - The compiled intermediate representation
§Returns

The generated CI configuration as a string

§Errors

Returns EmitterError if the IR cannot be transformed or serialized

Source

fn emit_expanded( &self, ir: &IntermediateRepresentation, ) -> EmitterResult<String>

Emit an expanded mode CI configuration.

Expanded mode generates a multi-job workflow where:

  • Each task becomes a separate job
  • Task dependencies map to job dependencies (needs: in GitHub Actions)
  • Phase tasks are included as steps within each job
§Arguments
  • ir - The compiled intermediate representation
§Returns

The generated CI configuration as a string

§Errors

Returns EmitterError if the IR cannot be transformed or serialized

Source

fn format_name(&self) -> &'static str

Get the format identifier for this emitter

Used for CLI flag matching (e.g., “buildkite”, “gitlab”, “tekton”)

Source

fn file_extension(&self) -> &'static str

Get the file extension for output files

Typically “yml” or “yaml” for most CI systems

Provided Methods§

Source

fn emit(&self, ir: &IntermediateRepresentation) -> EmitterResult<String>

Emit a CI configuration based on the mode in the IR.

This is the primary entry point for emission. It dispatches to emit_thin or emit_expanded based on ir.pipeline.mode.

§Arguments
  • ir - The compiled intermediate representation
§Returns

The generated CI configuration as a string

§Errors

Returns EmitterError if the IR cannot be transformed or serialized

Source

fn description(&self) -> &'static str

Get a human-readable description of this emitter

Source

fn validate(&self, ir: &IntermediateRepresentation) -> EmitterResult<()>

Validate the IR before emission

Override this to perform emitter-specific validation beyond the standard IR validation.

§Errors

Returns EmitterError::InvalidIR if validation fails

Implementors§