So I have a trait Searchable for things that can be optimized using branch&bound search or similar methods. The trait has three methods that are relevant for this question:
trait Searchable{
fn lower_bound(&self) -> Quality;
fn is_solved(&self) -> bool {
self.quality().is_some()
}
fn quality(&self) -> Option<Quality> {
if self.is_solved() {
Some(self.lower_bound())
} else {
None
}
// other methods
}
As you can see it is possible to express is_solved in terms of quality and the other way around.
Now this is nice since the implementing type can override one or both of these methods and get the rest for free. But if both methods are left with the default impl we have a problem since they recurse forever.
Does anyone know if there is any trick I can use to avoid the problem without giving up on the convenience of the default impls?
Thanks in advance!