shepherd-rs 0.2.0

Shepherd is a resilient, non-blocking orchestrator that persistently transforms and delivers data—built for remote, compute-heavy workloads.
Documentation
//! # Consume Attempt Trait
//!
//! This trait defines the behavior of consumption attempts in the shepherd
//! framework.
//!
//! ## Overview
//! - **ConsumeAttempt**: Represents an attempt to consume transformed data.
//! - **Identifiers**: Unique identifiers for requests, attempts, and
//!   consumption.
//! - **Context**: Includes consumption context and return context.
//!
//! ## Example
//! ```rust
//! struct MyConsumeAttempt;
//!
//! impl ConsumeAttempt for MyConsumeAttempt {
//!     // Implementation details...
//! }
//! ```

use std::error::Error;
use std::fmt::Debug;
use std::hash::Hash;

pub trait ConsumeAttempt: Send + Clone {
    type TransformRequestIdentifier: Eq + Hash + Send + Sync + Debug;
    type TransformAttemptIdentifier: Eq + Hash + Send + Sync + Debug;
    type Identifier: Eq
        + Hash
        + Send
        + Sync
        + Clone
        + Debug
        + Into<Self::TransformAttemptIdentifier>
        + Into<Self::TransformRequestIdentifier>;
    type ConsumeCtx: Send;
    type ConsumeVal: Send;
    type ReturnCtx: Send + Clone;

    type ConsumeError: Send + Error;

    fn request_id(&self) -> Self::TransformRequestIdentifier;
    fn attempt_id(&self) -> Self::TransformAttemptIdentifier;
    fn consume_id(&self) -> Self::Identifier;

    fn set_return_context(&mut self, ctx: Self::ReturnCtx);

    /// Given the ConsumeAttempt is the latest in the stream,
    /// what dynamic configs need to be updated, Key is always a
    /// string, value is always a `Vec<u8>` representing the serialized
    /// value.
    fn get_dyn_configs(&self) -> Vec<(String, Vec<u8>)>;
}

#[cfg(test)]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct NilCA;

#[cfg(test)]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct NilCAError;

#[cfg(test)]
impl std::fmt::Display for NilCAError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "NilCAError: This is a placeholder error for NilCA")
    }
}

#[cfg(test)]
impl std::error::Error for NilCAError {}

#[cfg(test)]
impl ConsumeAttempt for NilCA {
    type ConsumeCtx = ();
    type ConsumeError = NilCAError;
    type ConsumeVal = ();
    type Identifier = ();
    type ReturnCtx = ();
    type TransformAttemptIdentifier = ();
    type TransformRequestIdentifier = ();

    fn request_id(&self) -> Self::TransformRequestIdentifier { () }

    fn attempt_id(&self) -> Self::TransformAttemptIdentifier { () }

    fn consume_id(&self) -> Self::Identifier { () }

    fn set_return_context(&mut self, _ctx: Self::ReturnCtx) {}

    fn get_dyn_configs(&self) -> Vec<(String, Vec<u8>)> { vec![] }
}