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
use std::error::Error;
use std::fmt::Debug;
use std::hash::Hash;

/// A trait representing a transformation attempt in the shepherd-rs
/// processing system. Each transformation attempt is an attempt to resolve a
/// `TransformRequest` and produce an output based on the input provided.
///
/// The `Input` and `Output` types are generic, associated types, but they are
/// a little more complex than the `TransformRequest`'s `Input` and `Output`
/// types. A `TransformAttempt`'s `Input` to includes the `TransformRequest`'s
/// `Input`, but also includes a `CallCtx`, a attempt-specific additional data
/// needed for processing and an `Identifier` that uniquely identifies the
/// attempt.
pub trait TransformAttempt: Send + Sync + Clone {
    type TransformRequestIdentifier: Eq + Clone + Hash + Send + Sync + Debug;
    type Identifier: Eq
        + Clone
        + Hash
        + Send
        + Sync
        + Debug
        + Into<Self::TransformRequestIdentifier>;
    type CallCtx: Send;
    type CallArgsType: Send;
    type ReturnCtx: Send + Sync + Clone;
    type ReturnType: Send + Sync + Clone;

    type TransformError: Send + Sync + Clone + Error;

    type SendPackage = (Self::Identifier, Self::CallCtx, Self::CallArgsType);

    type ReturnPackage: Send + Sync + Clone = (
        Self::Identifier,
        Self::ReturnCtx,
        Result<Self::ReturnType, Self::TransformError>,
    );

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

    fn new(
        attempt_id: Self::Identifier,
        call_ctx: Self::CallCtx,
        call_val: Self::CallArgsType,
    ) -> Self;

    fn set_return_package(&mut self, return_pkg: Self::ReturnPackage);

    fn from_return_package(
        attempt_id: Self::Identifier,
        return_package: Self::ReturnPackage,
    ) -> Self;
}

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

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

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

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

#[cfg(test)]
impl TransformAttempt for NilTA {
    type CallArgsType = ();
    type CallCtx = ();
    type Identifier = ();
    type ReturnCtx = ();
    type ReturnPackage = (
        Self::Identifier,
        Self::ReturnCtx,
        Result<Self::ReturnType, Self::TransformError>,
    );
    type ReturnType = ();
    type SendPackage = (Self::Identifier, Self::CallCtx, Self::CallArgsType);
    type TransformError = NilTAError;
    type TransformRequestIdentifier = ();

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

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

    fn new(
        _attempt_id: Self::Identifier,
        _call_ctx: Self::CallCtx,
        _call_val: Self::CallArgsType,
    ) -> Self {
        NilTA
    }

    fn set_return_package(&mut self, _return_pkg: Self::ReturnPackage) {}

    fn from_return_package(
        _attempt_id: Self::Identifier,
        _return_package: Self::ReturnPackage,
    ) -> Self {
        NilTA
    }
}