ComparableMetric

Trait ComparableMetric 

Source
pub trait ComparableMetric:
    Any
    + Send
    + Sync {
    // Required methods
    fn value(&self) -> f64;
    fn compare(&self, other: &dyn ComparableMetric) -> Ordering;
    fn as_any(&self) -> &dyn Any;
}
Expand description

Trait for appraisal metrics that can be compared.

Implementers define how their values should be compared to determine which investment option is preferable through the compare method.

Required Methods§

Source

fn value(&self) -> f64

Returns the numeric value of this metric.

Source

fn compare(&self, other: &dyn ComparableMetric) -> Ordering

Compares this metric with another of the same type.

Returns Ordering::Less if self is better than other, Ordering::Greater if other is better, or Ordering::Equal if they are approximately equal.

§Panics

Panics if other is not the same concrete type as self.

Source

fn as_any(&self) -> &dyn Any

Helper for downcasting to enable type-safe comparison.

Implementors§