diff options
| author | Ben Blum <bblum@andrew.cmu.edu> | 2012-08-02 14:26:52 -0400 |
|---|---|---|
| committer | Ben Blum <bblum@andrew.cmu.edu> | 2012-08-02 14:31:58 -0400 |
| commit | 63b70b237049245c96e1a6ee077436a93fcd744b (patch) | |
| tree | e1239e0404113cff525b70a9ab21b6672d105783 | |
| parent | 97601cafc501447b4ea51ab5084b8657119463d6 (diff) | |
| download | rust-63b70b237049245c96e1a6ee077436a93fcd744b.tar.gz rust-63b70b237049245c96e1a6ee077436a93fcd744b.zip | |
Remove std::util
| -rw-r--r-- | src/libcore/util.rs | 9 | ||||
| -rw-r--r-- | src/libstd/map.rs | 11 | ||||
| -rw-r--r-- | src/libstd/std.rc | 3 | ||||
| -rw-r--r-- | src/libstd/util.rs | 21 |
4 files changed, 21 insertions, 23 deletions
diff --git a/src/libcore/util.rs b/src/libcore/util.rs index 0c7a54053b2..9321f6d242b 100644 --- a/src/libcore/util.rs +++ b/src/libcore/util.rs @@ -2,6 +2,9 @@ * Miscellaneous helpers for common patterns. */ +/// The identity function. +pure fn id<T>(+x: T) -> T { x } + /** * Swap the values at two mutable locations of the same type, without * deinitialising or copying either one. @@ -29,6 +32,12 @@ class noncopyable { mod tests { #[test] + fn identity_crisis() { + // Writing a test for the identity function. How did it come to this? + let x = ~[{mut a: 5, b: false}]; + assert x == id(copy x); + } + #[test] fn test_swap() { let mut x = 31337; let mut y = 42; diff --git a/src/libstd/map.rs b/src/libstd/map.rs index eb5c8cc95ab..902fe5aaf6e 100644 --- a/src/libstd/map.rs +++ b/src/libstd/map.rs @@ -75,6 +75,17 @@ trait map<K, V: copy> { fn each_value(fn(V) -> bool); } +mod util { + type rational = {num: int, den: int}; // : int::positive(*.den); + + pure fn rational_leq(x: rational, y: rational) -> bool { + // NB: Uses the fact that rationals have positive denominators WLOG: + + x.num * y.den <= y.num * x.den + } +} + + // FIXME (#2344): package this up and export it as a datatype usable for // external code that doesn't want to pay the cost of a box. mod chained { diff --git a/src/libstd/std.rc b/src/libstd/std.rc index 7270b0e9008..4f7cdecaebe 100644 --- a/src/libstd/std.rc +++ b/src/libstd/std.rc @@ -17,7 +17,7 @@ import core::*; export net, net_tcp, net_ip, net_url; export uv, uv_ll, uv_iotask, uv_global_loop; -export c_vec, util, timer; +export c_vec, timer; export bitv, deque, fun_treemap, list, map; export smallintmap, sort, treemap; export rope, arena, par; @@ -43,7 +43,6 @@ mod uv_global_loop; // Utility modules mod c_vec; -mod util; mod timer; diff --git a/src/libstd/util.rs b/src/libstd/util.rs deleted file mode 100644 index 1101be170ba..00000000000 --- a/src/libstd/util.rs +++ /dev/null @@ -1,21 +0,0 @@ -/// The identity function -pure fn id<T: copy>(x: T) -> T { x } - -/* FIXME (issue #141): See test/run-pass/constrained-type.rs. Uncomment - * the constraint once fixed. */ -/// A rational number -type rational = {num: int, den: int}; // : int::positive(*.den); - -pure fn rational_leq(x: rational, y: rational) -> bool { - // NB: Uses the fact that rationals have positive denominators WLOG: - - x.num * y.den <= y.num * x.den -} - -// Local Variables: -// mode: rust; -// fill-column: 78; -// indent-tabs-mode: nil -// c-basic-offset: 4 -// buffer-file-coding-system: utf-8-unix -// End: |
