diff options
| author | Simon Sapin <simon.sapin@exyr.org> | 2014-11-06 15:34:09 -0800 |
|---|---|---|
| committer | Simon Sapin <simon.sapin@exyr.org> | 2014-11-06 18:16:18 -0800 |
| commit | d8ab2f87c1705bff4f212cfb6d00ee4770abc1e1 (patch) | |
| tree | 9d5759279709234606251f185d8d26ee46505d73 | |
| parent | a22772d6a600f13d74e6562a36f80f0c81b5e013 (diff) | |
Add example impl in CLike docs. Fix 13752.
| -rw-r--r-- | src/libcollections/enum_set.rs | 22 |
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; |
