/****************************************************************************** * @file solver.rs * @author Joey Pollack * @date 2025/11/20 (y/m/d) * @modified 2025/11/20 (y/m/d) * @copyright Joseph R Pollack (2025) * @brief ******************************************************************************/ // pub trait SolutionValue> // { // fn get_solution_value() -> T; // // fn into() -> T; // Should be From() instead? https://doc.rust-lang.org/std/convert/trait.Into.html // } use std::collections::HashMap; pub trait Solver { fn init(&mut self, config: SolverState) -> Result<(), String>; fn solve(&mut self, input: String) -> Result; fn name(&self) -> String; } pub enum SolverOption { Verbose = 0x01, Debug = 0x02, } #[derive(Clone, Debug)] pub struct SolverState { options: u64, values: HashMap, } impl SolverState { pub fn new() -> Self { SolverState { options: 0, values: HashMap::new() } } pub fn set_option(self: &mut SolverState, opt: SolverOption) { self.options |= opt as u64; } pub fn clear_option(self: &mut SolverState, opt: SolverOption) { self.options &= !(opt as u64); } pub fn check_option(self: &SolverState, opt: SolverOption) -> bool { self.options & (opt as u64) != 0 } pub fn set_value(self: &mut SolverState, val: String, key: String) { self.values.insert(key, val); } pub fn get_value(self: &SolverState, key: String) -> String { self.values[&key].clone() } }