vc_processors/core/ext/
mod.rs

1//! This module provides wrappers to construct task producer & consumer.
2//! The producer sends tasks via stdin of the consumer, which should be a
3//! sub-process.
4
5use serde::{Deserialize, Serialize};
6
7#[cfg(feature = "ext-producer")]
8mod producer;
9#[cfg(feature = "ext-producer")]
10pub use producer::{dump_error_resp_env, BoxedFinalizeHook, BoxedPrepareHook, Producer, ProducerBuilder};
11
12mod consumer;
13pub use consumer::{run as run_consumer, run_with_processor as run_consumer_with_proc};
14
15/// Request contains the required data to be sent to the consumer.
16#[derive(Clone, Debug, Serialize, Deserialize)]
17pub struct Request<T> {
18    /// request id which should be maintained by the producer and used later to dispatch the response
19    pub id: u64,
20
21    /// the task itself
22    pub task: T,
23}
24
25/// Response contains the output for the specific task, and error message if exists.
26#[derive(Clone, Debug, Serialize, Deserialize)]
27pub struct Response<O> {
28    /// request id
29    pub id: u64,
30
31    /// error message if the task execution failed
32    pub err_msg: Option<String>,
33
34    /// output of the succeeded task execution
35    pub output: Option<O>,
36}
37
38#[inline]
39fn ready_msg(name: &str) -> String {
40    format!("{} processor ready", name)
41}