Remove std::util

This commit is contained in:
Ben Blum 2012-08-02 14:26:52 -04:00
parent 97601cafc5
commit 63b70b2370
4 changed files with 21 additions and 23 deletions

View file

@ -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.
@ -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;

View file

@ -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 {

View file

@ -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;

View file

@ -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: