Skip to main content

Reducer

Struct Reducer 

Source
pub struct Reducer<V> { /* private fields */ }
Expand description

A channel that applies a reducer function to combine values.

Unlike LastValue, this channel can accept multiple values during a single super-step and will combine them using the specified reducer.

§Type Parameters

  • V: The value type stored in this channel.

§Examples

ⓘ
use regula_core::channel::{Reducer, ReducerType, Channel};

// Create a reducer channel that appends to a vector
let mut channel: Reducer<Vec<String>> = Reducer::new(ReducerType::Append, None);

// Multiple updates are combined
channel.update(vec![vec!["a".to_string()]]).unwrap();
channel.update(vec![vec!["b".to_string()]]).unwrap();

// Result: ["a", "b"]

Implementations§

Source§

impl<V> Reducer<V>

Source

pub fn new(reducer_type: ReducerType, initial: Option<V>) -> Self

Create a new Reducer channel with the specified reducer type.

Source

pub fn with_custom(reducer_fn: ReducerFn<V>, initial: Option<V>) -> Self

Create a new Reducer channel with a custom reducer function.

Source

pub fn reducer_type(&self) -> &ReducerType

Get the reducer type.

Source

pub fn get_value(&self) -> Option<&V>

Get a reference to the current value.

Trait Implementations§

Source§

impl<T> Channel for Reducer<Vec<T>>
where T: Clone + Send + Sync + Serialize + DeserializeOwned + Debug + 'static,

Source§

type Value = Vec<T>

The type of value stored in this channel.
Source§

fn update(&mut self, values: Vec<Self::Value>) -> Result<bool>

Update the channel with new values. Read more
Source§

fn get(&self) -> Result<Self::Value>

Get the current value, if set.
Source§

fn is_set(&self) -> bool

Check if the channel has a value.
Source§

fn reset(&mut self)

Reset the channel to empty state.
Source§

fn spec(&self) -> ChannelSpec

Get the channel specification.
Source§

fn checkpoint(&self) -> Result<Option<Value>>

Serialize the channel value for checkpointing.
Source§

fn restore(&mut self, value: Option<Value>) -> Result<()>

Restore the channel from a checkpoint.
Source§

impl<V: Clone> Clone for Reducer<V>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<V: Debug> Debug for Reducer<V>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<V> !RefUnwindSafe for Reducer<V>

§

impl<V> !UnwindSafe for Reducer<V>

§

impl<V> Freeze for Reducer<V>
where Option<V>: Freeze, Option<Arc<dyn Fn(V, V) -> V + Send + Sync>>: Freeze, PhantomData<V>: Freeze,

§

impl<V> Send for Reducer<V>
where Option<V>: Send, Option<Arc<dyn Fn(V, V) -> V + Send + Sync>>: Send, PhantomData<V>: Send,

§

impl<V> Sync for Reducer<V>
where Option<V>: Sync, Option<Arc<dyn Fn(V, V) -> V + Send + Sync>>: Sync, PhantomData<V>: Sync,

§

impl<V> Unpin for Reducer<V>
where Option<V>: Unpin, Option<Arc<dyn Fn(V, V) -> V + Send + Sync>>: Unpin, PhantomData<V>: Unpin,

§

impl<V> UnsafeUnpin for Reducer<V>
where Option<V>: UnsafeUnpin, Option<Arc<dyn Fn(V, V) -> V + Send + Sync>>: UnsafeUnpin, PhantomData<V>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more