about summary refs log tree commit diff
path: root/src/libcore/uint-template.rs
diff options
context:
space:
mode:
authorBen Striegel <ben.striegel@gmail.com>2012-06-24 00:05:52 -0400
committerBrian Anderson <banderson@mozilla.com>2012-06-25 14:25:48 -0700
commit43a48ca5bba2698e253d6229139328d353276ee8 (patch)
tree559837ded01fd12ce960a1a29c1b2246a79b452a /src/libcore/uint-template.rs
parent07d568688c3a97866439735742bc0f489723a78a (diff)
Automatically export methods on core numeric types
Each numeric type now contains an extensions module that is automatically
exported. At the moment each extensions module contains only the impl for the
`num::num` iface. Other impls soon to follow (hopefully).
Diffstat (limited to 'src/libcore/uint-template.rs')
-rw-r--r--src/libcore/uint-template.rs24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/libcore/uint-template.rs b/src/libcore/uint-template.rs
index d5f0cc465c7..5d8c9415a77 100644
--- a/src/libcore/uint-template.rs
+++ b/src/libcore/uint-template.rs
@@ -12,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, num;
+export ord, eq, extensions;
 
 const min_value: T = 0 as T;
 const max_value: T = 0 as T - 1 as T;
@@ -65,16 +65,18 @@ impl eq of eq for T {
     }
 }
 
-impl num of num::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 neg()              -> T { ret -self;        }
-
-    fn to_int()         -> int { ret self as int; }
-    fn from_int(n: int) -> T   { ret n as T;      }
+mod extensions {
+    impl num of num::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 neg()              -> T { ret -self;        }
+
+        fn to_int()         -> int { ret self as int; }
+        fn from_int(n: int) -> T   { ret n as T;      }
+    }
 }
 
 #[doc = "