Skip to content

Commit d8ab2f8

Browse files
committed
Add example impl in CLike docs. Fix 13752.
1 parent a22772d commit d8ab2f8

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/libcollections/enum_set.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,27 @@ impl<E:CLike+fmt::Show> fmt::Show for EnumSet<E> {
4343
}
4444
}
4545

46-
/// An interface for casting C-like enum to uint and back.
46+
/**
47+
An interface for casting C-like enum to uint and back.
48+
A typically implementation is as below.
49+
50+
```{rust,ignore}
51+
#[repr(uint)]
52+
enum Foo {
53+
A, B, C
54+
}
55+
56+
impl CLike for Foo {
57+
fn to_uint(&self) -> uint {
58+
*self as uint
59+
}
60+
61+
fn from_uint(v: uint) -> Foo {
62+
unsafe { mem::transmute(v) }
63+
}
64+
}
65+
```
66+
*/
4767
pub trait CLike {
4868
/// Converts a C-like enum to a `uint`.
4969
fn to_uint(&self) -> uint;

0 commit comments

Comments
 (0)