typerat 0.0.4

Type-level rational numbers based on `typenum`.
Documentation
use crate::{Denominator, NonZeroUnsigned, Numerator, Q};
use typenum::{NInt, PInt};

/// The unary reciprocal operation.
pub trait Recip {
    /// The resulting type after applying the reciprocal operation.
    type Output;

    /// Performs the reciprocal operation.
    fn recip(self) -> Self::Output;
}

impl<Un, Ud> Recip for Q<PInt<Un>, PInt<Ud>>
where
    Un: NonZeroUnsigned,
    Ud: NonZeroUnsigned,
    PInt<Un>: Numerator<PInt<Ud>> + Denominator,
    PInt<Ud>: Denominator + Numerator<PInt<Un>>,
{
    type Output = Q<PInt<Ud>, PInt<Un>>;

    fn recip(self) -> Self::Output {
        Self::Output::new()
    }
}

impl<Un, Ud> Recip for Q<NInt<Un>, PInt<Ud>>
where
    Un: NonZeroUnsigned,
    Ud: NonZeroUnsigned,
    NInt<Un>: Numerator<PInt<Ud>>,
    PInt<Ud>: Denominator,
    NInt<Ud>: Numerator<PInt<Un>>,
    PInt<Un>: Denominator,
{
    type Output = Q<NInt<Ud>, PInt<Un>>;

    fn recip(self) -> Self::Output {
        Self::Output::new()
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use typenum::consts::*;

    #[test]
    fn test_recip() {
        // positive
        assert!(Q::<P1, P2>::new().recip() == Q::<P2>::new());

        // negative
        assert!(Q::<N1, P3>::new().recip() == Q::<N3>::new());
    }
}