eryon-core 0.0.4

The core modules of the eryon framework, providing essential functionality for computational entities.
/*
    Appellation: difference <module>
    Contrib: @FL03
*/

/// A binary operator defining the percent difference between two values where given input
/// is compared to the caller meaning the caller is said to be the _original_ value whilst
/// the input is said to be the _new_ value.
pub trait PercentDifference<Rhs = Self> {
    type Output;

    /// Computes the percent difference between two values.
    fn percent_diff(self, rhs: Rhs) -> Self::Output;
}

/*
 ************* Implementations *************
*/

impl<A, B, C> PercentDifference<B> for A
where
    C: core::ops::Div<A, Output = C>,
    for<'a> B: core::ops::Sub<&'a A, Output = C>,
{
    type Output = C;

    fn percent_diff(self, rhs: B) -> Self::Output {
        (rhs - &self) / self
    }
}