solverforge_scoring/stream/
factory.rs1use std::marker::PhantomData;
7
8use solverforge_core::score::Score;
9
10use super::collection_extract::{tracked, ChangeSource, CollectionExtract, TrackedExtract};
11use super::filter::TrueFilter;
12use super::UniConstraintStream;
13
14pub struct ConstraintFactory<S, Sc: Score> {
44 _phantom: PhantomData<(fn() -> S, fn() -> Sc)>,
45}
46
47impl<S, Sc> ConstraintFactory<S, Sc>
48where
49 S: Send + Sync + 'static,
50 Sc: Score + 'static,
51{
52 pub fn new() -> Self {
54 Self {
55 _phantom: PhantomData,
56 }
57 }
58
59 pub fn for_each<A, E>(self, extractor: E) -> UniConstraintStream<S, A, E, TrueFilter, Sc>
66 where
67 A: Clone + Send + Sync + 'static,
68 E: CollectionExtract<S, Item = A>,
69 {
70 UniConstraintStream::new(extractor)
71 }
72
73 pub fn for_each_tracked<A, E>(
74 self,
75 extractor: E,
76 change_source: ChangeSource,
77 ) -> UniConstraintStream<S, A, TrackedExtract<E>, TrueFilter, Sc>
78 where
79 A: Clone + Send + Sync + 'static,
80 E: CollectionExtract<S, Item = A>,
81 {
82 UniConstraintStream::new(tracked(extractor, change_source))
83 }
84}
85
86impl<S, Sc> Default for ConstraintFactory<S, Sc>
87where
88 S: Send + Sync + 'static,
89 Sc: Score + 'static,
90{
91 fn default() -> Self {
92 Self::new()
93 }
94}
95
96impl<S, Sc: Score> Clone for ConstraintFactory<S, Sc> {
97 fn clone(&self) -> Self {
98 Self {
99 _phantom: PhantomData,
100 }
101 }
102}
103
104impl<S, Sc: Score> std::fmt::Debug for ConstraintFactory<S, Sc> {
105 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
106 f.debug_struct("ConstraintFactory").finish()
107 }
108}