ubl_runtime/
ctx.rs

1//! Application context wrapper for emitting UBL events during DIM processing.
2use anyhow::Result;
3use ubl_ledger::UblWriter;
4use serde::Serialize;
5
6/// Contexto do app: escritor do ledger.
7pub struct AppCtx {
8    writer: UblWriter,
9}
10impl AppCtx {
11    /// Novo contexto
12    #[must_use]
13    #[allow(clippy::missing_const_for_fn)]
14    pub fn new(writer: UblWriter) -> Self {
15        Self { writer }
16    }
17    /// Log genérico no UBL
18    ///
19    /// # Errors
20    ///
21    /// - Propaga falhas de serialização ou I/O do writer
22    pub fn log<T: Serialize>(&self, kind: &str, payload: &T) -> Result<()> {
23        self.writer.append(kind, payload, None, None)?;
24        Ok(())
25    }
26    /// Eventos padrão
27    ///
28    /// # Errors
29    ///
30    /// - Propaga falhas de escrita no UBL
31    pub fn received(&self, ev: &crate::events::IntentReceived) -> Result<()> {
32        self.log("sirp.intent.received", ev)
33    }
34    /// Marca completude da intenção.
35    ///
36    /// # Errors
37    ///
38    /// - Propaga falhas de escrita no UBL
39    pub fn completed(&self, ev: &crate::events::IntentCompleted) -> Result<()> {
40        self.log("sirp.intent.completed", ev)
41    }
42}