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§
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.