coreon-core 0.1.0

Core abstractions for camel-rs: Exchange, Processor, Endpoint, Component, CamelContext.
Documentation
//! Exchange — the per-message state that flows through a route.

use crate::message::Message;
use std::collections::HashMap;

/// Message Exchange Pattern. Mirrors Camel's MEP but we only implement
/// InOnly and InOut for MVP.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
pub enum ExchangePattern {
    #[default]
    InOnly,
    InOut,
}

#[derive(Clone, Debug, Default)]
pub struct Exchange {
    pub pattern: ExchangePattern,
    pub r#in: Message,
    pub out: Option<Message>,
    /// Free-form properties attached to this exchange (route-scoped).
    pub properties: HashMap<String, String>,
}

impl Exchange {
    pub fn new(body: impl Into<crate::message::Body>) -> Self {
        Self {
            r#in: Message::new(body),
            ..Self::default()
        }
    }

    pub fn with_pattern(mut self, p: ExchangePattern) -> Self {
        self.pattern = p;
        self
    }

    /// Convenience accessor: the "effective" message is `out` if present,
    /// otherwise `in`. EIPs write to `out`; the pipeline swaps it into `in`
    /// before the next step if needed.
    pub fn effective_message(&self) -> &Message {
        self.out.as_ref().unwrap_or(&self.r#in)
    }

    /// Promote `out` → `in` between pipeline steps so the next Processor
    /// reads a single canonical input.
    pub fn advance(&mut self) {
        if let Some(out) = self.out.take() {
            self.r#in = out;
        }
    }
}