From de91d5d9e3016895690934f434623df8f26058d9 Mon Sep 17 00:00:00 2001 From: Wictor Lund Date: Thu, 1 Dec 2016 21:37:07 +0200 Subject: [PATCH] Added trait From for Ratio where T: Clone + Integer --- rational/src/lib.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rational/src/lib.rs b/rational/src/lib.rs index 938de46..ae01b2c 100644 --- a/rational/src/lib.rs +++ b/rational/src/lib.rs @@ -261,6 +261,13 @@ impl Ratio { } } +// From integer +impl From for Ratio where T: Clone + Integer { + fn from(x: T) -> Ratio { + Ratio::from_integer(x) + } +} + // Comparisons // Mathematically, comparing a/b and c/d is the same as comparing a*d and b*c, but it's very easy