Skip to main content

hm_plugin_sdk/
output.rs

1use hm_plugin_protocol::{BuildEvent, PluginError};
2
3/// Implemented by output-formatter plugins.
4///
5/// The host invokes [`OutputFormatter::on_event`] for every build event
6/// in order, then once at the end calls [`OutputFormatter::finalize`]
7/// for formatters that accumulate (`JUnit` XML, JSON arrays).
8pub trait OutputFormatter {
9    /// Handle a single build event.
10    ///
11    /// # Errors
12    /// Returns a [`PluginError`] if the formatter cannot process the
13    /// event (e.g. malformed input). The host renders the error and
14    /// aborts the formatter; the build itself is unaffected.
15    fn on_event(&self, event: BuildEvent) -> Result<(), PluginError>;
16
17    /// Optional. Default returns empty bytes. Streaming formatters
18    /// (human, json-lines) leave this alone; accumulating formatters
19    /// (junit) return the full document here.
20    ///
21    /// # Errors
22    /// Returns a [`PluginError`] if the formatter cannot serialise its
23    /// accumulated state.
24    fn finalize(&self) -> Result<Vec<u8>, PluginError> {
25        Ok(Vec::new())
26    }
27}