瀏覽代碼

Added trait From<T> for Ratio<T> where T: Clone + Integer

Wictor Lund 8 年之前
父節點
當前提交
de91d5d9e3
共有 1 個文件被更改,包括 7 次插入0 次删除
  1. 7 0
      rational/src/lib.rs

+ 7 - 0
rational/src/lib.rs

@@ -261,6 +261,13 @@ impl Ratio<BigInt> {
     }
 }
 
+// From integer
+impl<T> From<T> for Ratio<T> where T: Clone + Integer {
+    fn from(x: T) -> Ratio<T> {
+        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