about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLindsey Kuper <lindsey@rockstargirl.org>2012-07-02 17:11:26 -0700
committerLindsey Kuper <lindsey@rockstargirl.org>2012-07-02 17:12:30 -0700
commitd90a1dee4343305deb429150e79131abc8edcdc2 (patch)
treebd1dd2103188f070657b8dac55807784942453c6
parent43def0677aaf759e2d83d828b0318163d094c2d4 (diff)
downloadrust-d90a1dee4343305deb429150e79131abc8edcdc2.tar.gz
rust-d90a1dee4343305deb429150e79131abc8edcdc2.zip
Start sketching some traitorous code (xfail'd)
-rw-r--r--src/test/run-pass/traits.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/test/run-pass/traits.rs b/src/test/run-pass/traits.rs
new file mode 100644
index 00000000000..c50d9bf96ac
--- /dev/null
+++ b/src/test/run-pass/traits.rs
@@ -0,0 +1,46 @@
+//xfail-test
+
+// Sketching traits.
+
+// methods with no implementation are required; methods with an
+// implementation are provided.  No "req" keyword necessary.
+trait Eq {
+    fn eq(a: self) -> bool;
+
+    fn neq(a: self) -> bool {
+        !self.neq(a)
+    }
+}
+
+// The `<` is pronounced `extends`.  Also under consideration is `<:`.
+// Just using `:` is frowned upon, because (paraphrasing dherman) `:`
+// is supposed to separate things from different universes.
+trait Ord < Eq {
+
+    fn lt(a: self) -> bool;
+
+    fn lte(a: self) -> bool {
+        self.lt(a) || self.eq(a)
+    }
+
+    fn gt(a: self) -> bool {
+        !self.lt(a) && !self.eq(a)
+    }
+
+    fn gte(a: self) -> bool {
+        !self.lt(a)
+    }
+}
+
+// pronounced "impl of Ord for int" -- not sold on this yet
+impl int: Ord {
+    fn lt(a: self) -> bool {
+        self < a
+    }
+
+    // is this the place to put this?
+    fn eq(a: self) -> bool {
+        self == a
+    }
+}
+