1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
use alloc::boxed::Box;
use core::{future::Future, pin::Pin};

#[cfg(not(feature = "with-futures"))]
pub type SolverFuture<'a, E> = Pin<Box<dyn Future<Output = Result<(), E>> + 'a>>;

#[cfg(feature = "with-futures")]
pub type SolverFuture<'a, E> = Pin<Box<dyn Future<Output = Result<(), E>> + Send + Sync + 'a>>;

pub trait Solver<P> {
  type Error;

  /// Do solving work after stoping criteria verification.
  fn after_iter<'a>(&'a mut self, p: &'a mut P) -> SolverFuture<'a, Self::Error>;

  /// Do solving work before stoping criteria verification.
  fn before_iter<'a>(&'a mut self, p: &'a mut P) -> SolverFuture<'a, Self::Error>;

  fn finished(&mut self, _: &mut P) {}

  fn init(&mut self, _: &mut P) {}
}