pumpkin_core/engine/termination/mod.rs
1//! A [`TerminationCondition`] is a condition which is polled by the solver during the search
2//! process. It indicates when the solver should stop, even if no definitive conclusions have been
3//! made. The most common example would be [`time_budget::TimeBudget`], which gives the solver a
4//! certain time budget to complete its search.
5
6use std::ops::DerefMut;
7
8pub(crate) mod combinator;
9pub(crate) mod indefinite;
10pub(crate) mod time_budget;
11
12/// The central trait that defines a termination condition. A termination condition determines when
13/// the solver should give up searching for solutions.
14///
15/// # Notes
16/// - Any `Box<dyn TerminationCondition>` is a valid implementation of `TerminationCondition`.
17pub trait TerminationCondition {
18 /// Returns `true` when the solver should stop, `false` otherwise.
19 fn should_stop(&mut self) -> bool;
20}
21
22impl<T: TerminationCondition> TerminationCondition for Option<T> {
23 fn should_stop(&mut self) -> bool {
24 match self {
25 Some(t) => t.should_stop(),
26 None => false,
27 }
28 }
29}
30
31impl TerminationCondition for Box<dyn TerminationCondition> {
32 fn should_stop(&mut self) -> bool {
33 self.deref_mut().should_stop()
34 }
35}