Hi there, I have the following code
// Main struct for Solver
pub struct Solver<'a> {
pub problem: &'a Problem,
pub method: String
}
// Functions for Solver
impl Solver<'_> {
pub fn run (&self) {
// Print
println!("Solving in Solver");
let mut optimiser = match self.method.as_str() {
"GeneticAlgorithm" => GeneticAlgorithm::new {
problem: self.problem,
},
_ => panic!()
};
optimiser.run();
}
}
pub struct GeneticAlgorithm<'a> {
pub problem: &'a Problem,
initialization: Initialization,
termination: Termination,
is_initialized: bool
}
impl<'a> GeneticAlgorithm<'a> {
fn new(problem: &'a Problem) -> Self {
Self {
problem: problem,
initialization: Initialization {
sampling: 3,
repair: 3,
eliminate_duplicates: 3
},
termination: Termination::new(),
is_initialized: false
}
}
}
where I am trying to create a solver using struct. The solver requires parameters such as initialization and termination but I only want to pass the problem, and want the other parameters to take default values. The error i get is
error[E0223]: ambiguous associated type
--> src/problem.rs:18:35
|
18 | "GeneticAlgorithm" => GeneticAlgorithm::new {
| ^^^^^^^^^^^^^^^^^^^^^ help: use fully-qualified syntax: `<GeneticAlgorithm<'_> as Trait>::new`
but I cannot seem to work out how to overcome my issue. Any help would be greatly appreciated!