소스 검색

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