Skip to main content

TypedOperation

Trait TypedOperation 

Source
pub trait TypedOperation: Operation {
    type Output: DeserializeOwned;
}
Expand description

A typed extension of Operation that declares a concrete output type.

Implement this alongside Operation when the step output has a known Rust type. Consumers can then deserialize the output without guessing the shape.

§Examples

use ironflow_core::operation::{Operation, OperationContext, TypedOperation};
use ironflow_core::error::OperationError;
use serde::Deserialize;
use serde_json::{Value, json};
use std::future::Future;
use std::pin::Pin;

#[derive(Debug, Deserialize)]
struct IssueCreated {
    iid: u64,
    url: String,
}

struct CreateIssue;

impl Operation for CreateIssue {
    fn kind(&self) -> &str { "gitlab" }
    fn execute<'a>(
        &'a self,
        _ctx: &'a OperationContext,
    ) -> Pin<Box<dyn Future<Output = Result<Value, OperationError>> + Send + 'a>> {
        Box::pin(async { Ok(json!({"iid": 42, "url": "https://gitlab.com/issues/42"})) })
    }
}

impl TypedOperation for CreateIssue {
    type Output = IssueCreated;
}

Required Associated Types§

Source

type Output: DeserializeOwned

The concrete output type that Operation::execute produces.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§