Skip to content

Restrict generic type of Ratio #55

@maxbla

Description

@maxbla

We effectively restrict the type of Ratios by only impling new() and new_raw() on T: Clone + Integer. This appears to work well, but putting the same restrictions on the T in the Ratio declaration itself would make this requirement more explicit.
e.g.

/// Represents the ratio between two numbers.
#[derive(Copy, Clone, Debug)]
#[allow(missing_docs)]
pub struct Ratio<T: Clone + Integer> {
    /// Numerator.
    numer: T,
    /// Denominator.
    denom: T,
}

Testing out this change now, the compiler complains for every method in this library that uses Ratio where T is not Clone and Integer (for example Display).

Unlike many of the issues I have been submitting recently, I believe this would not be a breaking change.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions