about summary refs log tree commit diff
path: root/src/libcore/tuple.rs
diff options
context:
space:
mode:
authorLenny222 <github@kudling.de>2012-01-17 19:43:29 +0100
committerNiko Matsakis <niko@alum.mit.edu>2012-01-17 10:51:43 -0800
commitb19fdcced22d36bd50974e1da3062439e8a656b2 (patch)
tree86eec2a7af794cfcdba23cccf7521b9c7f7e6420 /src/libcore/tuple.rs
parent106dcf7b925a1ac654d5df36ea6227fead493124 (diff)
downloadrust-b19fdcced22d36bd50974e1da3062439e8a656b2.tar.gz
rust-b19fdcced22d36bd50974e1da3062439e8a656b2.zip
libstd => libcore
Diffstat (limited to 'src/libcore/tuple.rs')
-rw-r--r--src/libcore/tuple.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/libcore/tuple.rs b/src/libcore/tuple.rs
new file mode 100644
index 00000000000..9d24f428d42
--- /dev/null
+++ b/src/libcore/tuple.rs
@@ -0,0 +1,28 @@
+/*
+Module: tuple
+*/
+
+// FIXME #1546: Would rather write fst<T, U>(+pair: (T, U)) -> T
+fn first<T:copy, U:copy>(pair: (T, U)) -> T {
+    let (t, _) = pair;
+    ret t;
+}
+
+fn second<T:copy, U:copy>(pair: (T, U)) -> U {
+    let (_, u) = pair;
+    ret u;
+}
+
+fn swap<T:copy, U:copy>(pair: (T, U)) -> (U, T) {
+    let (t, u) = pair;
+    ret (u, t);
+}
+
+
+#[test]
+fn test_tuple() {
+    assert first((948, 4039.48)) == 948;
+    assert second((34.5, "foo")) == "foo";
+    assert swap(('a', 2)) == (2, 'a');
+}
+