use std::marker::PhantomData;
use solverforge_core::score::Score;
use super::collection_extract::{tracked, ChangeSource, CollectionExtract, TrackedExtract};
use super::filter::TrueFilter;
use super::UniConstraintStream;
pub struct ConstraintFactory<S, Sc: Score> {
_phantom: PhantomData<(fn() -> S, fn() -> Sc)>,
}
impl<S, Sc> ConstraintFactory<S, Sc>
where
S: Send + Sync + 'static,
Sc: Score + 'static,
{
pub fn new() -> Self {
Self {
_phantom: PhantomData,
}
}
pub fn for_each<A, E>(self, extractor: E) -> UniConstraintStream<S, A, E, TrueFilter, Sc>
where
A: Clone + Send + Sync + 'static,
E: CollectionExtract<S, Item = A>,
{
UniConstraintStream::new(extractor)
}
pub fn for_each_tracked<A, E>(
self,
extractor: E,
change_source: ChangeSource,
) -> UniConstraintStream<S, A, TrackedExtract<E>, TrueFilter, Sc>
where
A: Clone + Send + Sync + 'static,
E: CollectionExtract<S, Item = A>,
{
UniConstraintStream::new(tracked(extractor, change_source))
}
}
impl<S, Sc> Default for ConstraintFactory<S, Sc>
where
S: Send + Sync + 'static,
Sc: Score + 'static,
{
fn default() -> Self {
Self::new()
}
}
impl<S, Sc: Score> Clone for ConstraintFactory<S, Sc> {
fn clone(&self) -> Self {
Self {
_phantom: PhantomData,
}
}
}
impl<S, Sc: Score> std::fmt::Debug for ConstraintFactory<S, Sc> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ConstraintFactory").finish()
}
}