From 63b70b237049245c96e1a6ee077436a93fcd744b Mon Sep 17 00:00:00 2001 From: Ben Blum Date: Thu, 2 Aug 2012 14:26:52 -0400 Subject: [PATCH] Remove std::util --- src/libcore/util.rs | 9 +++++++++ src/libstd/map.rs | 11 +++++++++++ src/libstd/std.rc | 3 +-- src/libstd/util.rs | 21 --------------------- 4 files changed, 21 insertions(+), 23 deletions(-) delete mode 100644 src/libstd/util.rs diff --git a/src/libcore/util.rs b/src/libcore/util.rs index 0c7a54053b25..9321f6d242b6 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(+x: T) -> T { x } + /** * Swap the values at two mutable locations of the same type, without * deinitialising or copying either one. @@ -28,6 +31,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; diff --git a/src/libstd/map.rs b/src/libstd/map.rs index eb5c8cc95ab1..902fe5aaf6e1 100644 --- a/src/libstd/map.rs +++ b/src/libstd/map.rs @@ -75,6 +75,17 @@ trait map { 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 7270b0e9008f..4f7cdecaebeb 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 1101be170bac..000000000000 --- a/src/libstd/util.rs +++ /dev/null @@ -1,21 +0,0 @@ -/// The identity function -pure fn id(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: