Skip to main content

Callback

Type Alias Callback 

Source
pub type Callback<'a> = Box<dyn FnMut(HashMap<VarName, Constant>) -> bool + 'a>;
Expand description

The callback type used by run_minion.

Called by Minion whenever a solution is found. The input is a HashMap of all named variables along with their value.

Return true to continue searching, false to stop.

Since this is a boxed closure, it can capture state from its environment, eliminating the need for global or thread-local state in callers.

§Examples

  use minion_sys::ast::*;
  use minion_sys::run_minion;
  use std::collections::HashMap;

  let mut all_solutions: Vec<HashMap<VarName,Constant>> = vec![];

  let callback = Box::new(|solutions: HashMap<VarName,Constant>| -> bool {
      all_solutions.push(solutions);
      true
  });

  // Build and run the model.
  let mut model = Model::new();

  // ... omitted for brevity ...

  let _solver_ctx = run_minion(model, callback).expect("Error occurred");

  let solution_set_1 = &all_solutions[0];
  let x1 = solution_set_1.get("x").unwrap();
  let y1 = solution_set_1.get("y").unwrap();
  let z1 = solution_set_1.get("z").unwrap();

Aliased Type§

pub struct Callback<'a>(/* private fields */);

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 16 bytes