about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSimon Sapin <simon.sapin@exyr.org>2014-11-06 15:34:09 -0800
committerSimon Sapin <simon.sapin@exyr.org>2014-11-06 18:16:18 -0800
commitd8ab2f87c1705bff4f212cfb6d00ee4770abc1e1 (patch)
tree9d5759279709234606251f185d8d26ee46505d73
parenta22772d6a600f13d74e6562a36f80f0c81b5e013 (diff)
Add example impl in CLike docs. Fix 13752.
-rw-r--r--src/libcollections/enum_set.rs22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/libcollections/enum_set.rs b/src/libcollections/enum_set.rs
index 93dbb7e8b20..1acdaef9c91 100644
--- a/src/libcollections/enum_set.rs
+++ b/src/libcollections/enum_set.rs
@@ -43,7 +43,27 @@ impl<E:CLike+fmt::Show> fmt::Show for EnumSet<E> {
     }
 }
 
-/// An interface for casting C-like enum to uint and back.
+/**
+An interface for casting C-like enum to uint and back.
+A typically implementation is as below.
+
+```{rust,ignore}
+#[repr(uint)]
+enum Foo {
+    A, B, C
+}
+
+impl CLike for Foo {
+    fn to_uint(&self) -> uint {
+        *self as uint
+    }
+
+    fn from_uint(v: uint) -> Foo {
+        unsafe { mem::transmute(v) }
+    }
+}
+```
+*/
 pub trait CLike {
     /// Converts a C-like enum to a `uint`.
     fn to_uint(&self) -> uint;