提交 d8ab2f87 编写于 作者: S Simon Sapin

Add example impl in CLike docs. Fix 13752.

上级 a22772d6
......@@ -43,7 +43,27 @@ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
}
}
/// 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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册