Skip to main content

co_primitives/types/
reducer.rs

1// SPDX-License-Identifier: AGPL-3.0-only
2// Copyright (C) 2026 1io BRANDGUARDIAN GmbH
3
4use crate::Tags;
5use cid::Cid;
6use serde::{Deserialize, Serialize};
7
8#[derive(Debug, Serialize, Deserialize)]
9pub struct ReducerInput {
10	/// Source state.
11	#[serde(default, skip_serializing_if = "Option::is_none")]
12	pub state: Option<Cid>,
13
14	/// [`crate::ReducerAction`] to reduce.
15	pub action: Cid,
16}
17
18#[derive(Debug, Serialize, Deserialize)]
19pub struct ReducerOutput {
20	/// Result state.
21	#[serde(default, skip_serializing_if = "Option::is_none")]
22	pub state: Option<Cid>,
23
24	/// Error if the reducer has failed.
25	#[serde(default, skip_serializing_if = "Option::is_none")]
26	pub error: Option<String>,
27
28	/// Reducer metadata.
29	/// Tags retuned here will be merged into core tags.
30	#[serde(default, skip_serializing_if = "Tags::is_empty")]
31	pub tags: Tags,
32}