use alloc::vec::Vec;
use crate::{Domain, Domains, Inconsistent, Propagator, Rule};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PropagatorRule<P> {
name: &'static str,
cost: u32,
propagators: Vec<P>,
}
impl<P> PropagatorRule<P> {
#[must_use]
pub fn new(name: &'static str, cost: u32, propagators: impl IntoIterator<Item = P>) -> Self {
Self {
name,
cost,
propagators: propagators.into_iter().collect(),
}
}
}
impl<D: Domain, P: Propagator<D>> Rule<D> for PropagatorRule<P> {
fn name(&self) -> &str {
self.name
}
fn cost(&self) -> u32 {
self.cost
}
fn apply(&self, domains: &mut Domains<D>) -> Result<(), Inconsistent> {
let mut scratch = P::Scratch::default();
self.propagators
.iter()
.try_for_each(|propagator| propagator.propagate(domains, &mut scratch))
}
}