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
//! # Transform Attempt Creator Trait
//!
//! This trait defines the behavior for creating transformation attempts in the
//! shepherd framework.
//!
//! ## Overview
//! - **TransformAttemptCreator**: Converts transformation requests into
//!   transformation attempts.
//! - **Error Handling**: Provides mechanisms for handling errors during attempt
//!   creation.
//!
//! ## Example
//! ```rust
//! struct MyAttemptCreator;
//!
//! impl TransformAttemptCreator for MyAttemptCreator {
//!     // Implementation details...
//! }
//! ```

use std::error::Error;

use async_trait::async_trait;

use crate::config::Config;
use crate::transform::{TransformAttempt, TransformRequest};

#[async_trait]
pub trait TransformAttemptCreator: Send {
    type Input: Send;
    type Output: Send;
    type TransformRequest: TransformRequest<Input = Self::Input, Output = Self::Output>;
    type TransformAttempt: TransformAttempt<CallArgsType = Self::Input, ReturnType = Self::Output>;
    type TransformAttemptCreationError: Error + Send + Sync;

    async fn new(config: std::sync::Arc<tokio::sync::Mutex<impl Config>>) -> Self
    where
        Self: Sized;

    /// Converts a `TransformRequest` into a `TransformAttempt`.
    async fn create_new_attempt(
        &mut self,
        request: &Self::TransformRequest,
    ) -> Result<Self::TransformAttempt, Self::TransformAttemptCreationError>;

    /// Converts a `TransformRequest` into a `TransformAttempt`.
    async fn create_new_reattempt(
        &mut self,
        request: <Self::TransformAttempt as TransformAttempt>::Identifier,
        error: <Self::TransformAttempt as TransformAttempt>::ReturnPackage,
    ) -> Result<Self::TransformAttempt, Self::TransformAttemptCreationError>;
}