about summary refs log tree commit diff
path: root/src/libcore/uint-template.rs
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2012-06-07 16:08:38 -0700
committerPatrick Walton <pcwalton@mimiga.net>2012-06-07 16:08:38 -0700
commit3d7400f3accfc3da6f1e699770c69884bee1c664 (patch)
tree356d7103fed6f494da8ce2bcee344e93e230f88c /src/libcore/uint-template.rs
parentd542e67827e0ad1a3df5fd248d9c09997b5dcbba (diff)
Add a Num typeclass
Diffstat (limited to 'src/libcore/uint-template.rs')
-rw-r--r--src/libcore/uint-template.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/libcore/uint-template.rs b/src/libcore/uint-template.rs
index 7126fb3d007..9d658605f5a 100644
--- a/src/libcore/uint-template.rs
+++ b/src/libcore/uint-template.rs
@@ -1,5 +1,6 @@
 import T = inst::T;
 import cmp::{eq, ord};
+import num::num;
 
 export min_value, max_value;
 export min, max;
@@ -11,7 +12,7 @@ export range;
 export compl;
 export to_str, to_str_bytes;
 export from_str, from_str_radix, str, parse_buf;
-export ord, eq;
+export ord, eq, num;
 
 const min_value: T = 0 as T;
 const max_value: T = 0 as T - 1 as T;
@@ -63,6 +64,17 @@ impl eq of eq for T {
     }
 }
 
+impl num of num for T {
+    fn add(&&other: T)    -> T { ret self + other; }
+    fn sub(&&other: T)    -> T { ret self - other; }
+    fn mul(&&other: T)    -> T { ret self * other; }
+    fn div(&&other: T)    -> T { ret self / other; }
+    fn modulo(&&other: T) -> T { ret self % other; }
+
+    fn to_int()         -> int { ret self as int; }
+    fn from_int(n: int) -> T   { ret n as T;      }
+}
+
 #[doc = "
 Parse a buffer of bytes