I am finding myself in a situation where I'd like to select one from among several impl Ord
definitions at runtime, which I understand is not possible, and am wondering what the idiomatic approach would be to solving the actual problem: I'm implementing a best-first heuristic search algorithm for forward state-space search, and I want to be able to provide an arbitrary number of node prioritization schemes from which the user can select at runtime.
Approach Idea 1: instead of impl Ord
on my search Node
struct, parameterize the priority queue data structure with a comparator function fn(&Node, &Node) -> std::cmp::Ordering
, and define such a function for each prioritization scheme.
Approach Idea 2: define separate wrappers NodeA
, NodeB
, etc., each with corresponding impl Ord
, for each prioritization scheme.
Pros/cons of each approach? Suggestions for other approaches? Mistakes in thinking/gaps in understanding?