Skip to content

Commit

Permalink
Add example impl in CLike docs. Fix 13752.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSapin committed Nov 7, 2014
1 parent a22772d commit d8ab2f8
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/libcollections/enum_set.rs
Expand Up @@ -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;
Expand Down

1 comment on commit d8ab2f8

@alexcrichton
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+

Please sign in to comment.