about summary refs log tree commit diff
path: root/src/lib
diff options
context:
space:
mode:
authorMarijn Haverbeke <marijnh@gmail.com>2011-07-08 16:27:55 +0200
committerMarijn Haverbeke <marijnh@gmail.com>2011-07-11 11:01:54 +0200
commit86ee3454a1e49b0b913f37c2c52e79d68cae5410 (patch)
treefbb448de5295ab46b6894117597fdb51d2f28001 /src/lib
parent4d325b1a15126c6aa9f97d510a11d93d4ac2ad53 (diff)
downloadrust-86ee3454a1e49b0b913f37c2c52e79d68cae5410.tar.gz
rust-86ee3454a1e49b0b913f37c2c52e79d68cae5410.zip
Implement or-patterns in case clauses
You can now say

    expr_move(?dst, ?src) | expr_assign(?dst, ?src) { ... }

to match both expr_move and expr_assign. The names, types, and number
of bound names have to match in all the patterns.

Closes #449.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/ivec.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/lib/ivec.rs b/src/lib/ivec.rs
index cd55793a66e..3c21b476775 100644
--- a/src/lib/ivec.rs
+++ b/src/lib/ivec.rs
@@ -206,6 +206,15 @@ fn all[T](fn(&T)->bool f, &T[] v) -> bool {
     ret true;
 }
 
+fn member[T](&T x, &T[] v) -> bool {
+    for (T elt in v) { if (x == elt) { ret true; } }
+    ret false;
+}
+
+fn find[T](fn(&T) -> bool  f, &T[] v) -> option::t[T] {
+    for (T elt in v) { if (f(elt)) { ret some[T](elt); } }
+    ret none[T];
+}
 
 mod unsafe {
     fn copy_from_buf[T](&mutable T[] v, *T ptr, uint count) {