Skip to content

Commit b64ea06

Browse files
committed
---
yaml --- r: 22919 b: refs/heads/master c: 63b70b2 h: refs/heads/master i: 22917: a5b8a95 22915: 906d13b 22911: e663af9 v: v3
1 parent 251df64 commit b64ea06

File tree

5 files changed

+22
-24
lines changed

5 files changed

+22
-24
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 97601cafc501447b4ea51ab5084b8657119463d6
2+
refs/heads/master: 63b70b237049245c96e1a6ee077436a93fcd744b
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/src/libcore/util.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
* Miscellaneous helpers for common patterns.
33
*/
44

5+
/// The identity function.
6+
pure fn id<T>(+x: T) -> T { x }
7+
58
/**
69
* Swap the values at two mutable locations of the same type, without
710
* deinitialising or copying either one.
@@ -28,6 +31,12 @@ class noncopyable {
2831
}
2932

3033
mod tests {
34+
#[test]
35+
fn identity_crisis() {
36+
// Writing a test for the identity function. How did it come to this?
37+
let x = ~[{mut a: 5, b: false}];
38+
assert x == id(copy x);
39+
}
3140
#[test]
3241
fn test_swap() {
3342
let mut x = 31337;

trunk/src/libstd/map.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ trait map<K, V: copy> {
7575
fn each_value(fn(V) -> bool);
7676
}
7777

78+
mod util {
79+
type rational = {num: int, den: int}; // : int::positive(*.den);
80+
81+
pure fn rational_leq(x: rational, y: rational) -> bool {
82+
// NB: Uses the fact that rationals have positive denominators WLOG:
83+
84+
x.num * y.den <= y.num * x.den
85+
}
86+
}
87+
88+
7889
// FIXME (#2344): package this up and export it as a datatype usable for
7990
// external code that doesn't want to pay the cost of a box.
8091
mod chained {

trunk/src/libstd/std.rc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import core::*;
1717

1818
export net, net_tcp, net_ip, net_url;
1919
export uv, uv_ll, uv_iotask, uv_global_loop;
20-
export c_vec, util, timer;
20+
export c_vec, timer;
2121
export bitv, deque, fun_treemap, list, map;
2222
export smallintmap, sort, treemap;
2323
export rope, arena, par;
@@ -43,7 +43,6 @@ mod uv_global_loop;
4343
// Utility modules
4444

4545
mod c_vec;
46-
mod util;
4746
mod timer;
4847

4948

trunk/src/libstd/util.rs

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)