Commit

Trait Commit 

Source
pub trait Commit {
    // Required method
    fn commit(&self, from: Self);
}
Expand description

Trait for types that can be committed from a child to a parent during nesting.

When a nested iterator commits, this trait controls how the supplemental data flows from the child to the parent. The default implementations for (), Rc<T>, and Arc<T> are no-ops, meaning the data doesn’t propagate back.

The parent is immutable (&self) and the child is consumed by value. The implementor must use interior mutability (e.g., Cell, RefCell) if they need to mutate the parent.

§Examples

use shadow_counted::Commit;
use std::cell::Cell;

#[derive(Clone, Default)]
struct Counter {
    count: Cell<u32>,
}

impl Commit for Counter {
    fn commit(&self, from: Self) {
        self.count.set(self.count.get() + from.count.get());
    }
}

Required Methods§

Source

fn commit(&self, from: Self)

Called when a nested iterator commits to its parent. The implementation should merge/update the parent’s state using interior mutability.

§Arguments
  • from - The child’s supplemental data (consumed by value)

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Commit for ()

Source§

fn commit(&self, _from: Self)

Source§

impl<T> Commit for Rc<T>

Source§

fn commit(&self, _from: Self)

Source§

impl<T> Commit for Arc<T>

Source§

fn commit(&self, _from: Self)

Implementors§