Skip to content

Commit 45f70e2

Browse files
committed
---
yaml --- r: 20798 b: refs/heads/snap-stage3 c: 90ce3d9 h: refs/heads/master v: v3
1 parent 5ca98b1 commit 45f70e2

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: e430a699f2c60890d9b86069fd0c68a70ece7120
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 6fdd1ef9b18039eb29d8c8ba322883a565e94e43
4+
refs/heads/snap-stage3: 90ce3d94e45233f8aa49e40b1e8a2efc7a0f35ef
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libcore/core.rc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ mod option_iter {
179179
mod result;
180180
mod to_str;
181181
mod to_bytes;
182+
mod util;
183+
184+
// Data structure modules
185+
182186
mod dvec;
183187
#[path="iter-trait"]
184188
mod dvec_iter {
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* Miscellaneous helpers for common patterns.
3+
*/
4+
5+
/**
6+
* Swap the values at two mutable locations of the same type, without
7+
* deinitialising or copying either one.
8+
*/
9+
fn swap<T>(x: &mut T, y: &mut T) {
10+
*x <-> *y;
11+
}
12+
13+
/**
14+
* Replace the value at a mutable location with a new one, returning the old
15+
* value, without deinitialising or copying either one.
16+
*/
17+
fn replace<T>(dest: &mut T, +src: T) -> T {
18+
let mut tmp = src;
19+
swap(dest, &mut tmp);
20+
tmp
21+
}
22+
23+
/// A non-copyable dummy type.
24+
class noncopyable {
25+
i: ();
26+
new() { self.i = (); }
27+
drop { }
28+
}
29+
30+
mod tests {
31+
#[test]
32+
fn test_swap() {
33+
let mut x = 31337;
34+
let mut y = 42;
35+
swap(&mut x, &mut y);
36+
assert x == 42;
37+
assert y == 31337;
38+
}
39+
#[test]
40+
fn test_replace() {
41+
let mut x = some(noncopyable());
42+
let y = replace(&mut x, none);
43+
assert x.is_none();
44+
assert y.is_some();
45+
}
46+
}

0 commit comments

Comments
 (0)