routee_compass/plugin/output/
output_plugin.rs

1use super::output_plugin_error::OutputPluginError;
2use crate::app::compass::CompassAppError;
3use crate::app::search::SearchAppResult;
4use routee_compass_core::algorithm::search::SearchInstance;
5
6/// Performs some kind of post-processing on a search result. The result JSON is available
7/// to the plugin as a reference which was potentially modified upstream by another output
8/// plugin. The plugin will output a modified version of the JSON as a result.
9///
10/// A simple No-operation [`OutputPlugin`] would simply clone its JSON argument.
11///
12/// # Default OutputPlugins
13///
14/// The following default set of output plugin builders are found in the [`super::default`] module:
15///
16/// * [summary] - simple plugin appends cost and distance to result
17/// * [traversal] - fully-featured plugin for traversal outputs in different formats
18/// * [uuid] - attach the original graph ids to a result
19///
20/// [summary]: super::default::summary::builder::SummaryOutputPluginBuilder
21/// [traversal]: super::default::traversal::builder::TraversalPluginBuilder
22/// [uuid]: super::default::uuid::builder::UUIDOutputPluginBuilder
23pub trait OutputPlugin: Send + Sync {
24    /// Applies this [`OutputPlugin`] to a search result, passing along a JSON
25    /// that will replace the `output` JSON argument.
26    ///
27    /// # Arguments
28    ///
29    /// * `output` - the search result passed to this plugin
30    /// * `result` - the result of the search via the [internal representation].
31    ///   this is passed as a `Result` as the search may have failed.
32    ///
33    /// # Returns
34    ///
35    /// The modified JSON or an error
36    ///
37    /// [internal representation]: crate::app::search::SearchAppResult
38    fn process(
39        &self,
40        output: &mut serde_json::Value,
41        result: &Result<(SearchAppResult, SearchInstance), CompassAppError>,
42    ) -> Result<(), OutputPluginError>;
43}