1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
//! The module with auxiliary tools to construct `Goal` trait objects. /// Struct to convert (wrap) function to `Goal` trait. pub struct GoalFromFunction<T> { function: fn(&T) -> f64, } impl<T> GoalFromFunction<T> { /// Constructor. pub fn new(function: fn(&T) -> f64) -> Self { Self { function, } } } impl<T> super::Goal<T> for GoalFromFunction<T> { fn get(&self, chromosomes: &T) -> f64 { (self.function)(chromosomes) } }