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

5 comments on commit d8ab2f8

@bors
Copy link
Contributor

@bors bors commented on d8ab2f8 Nov 7, 2014

Choose a reason for hiding this comment

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

saw approval from alexcrichton
at SimonSapin@d8ab2f8

@bors
Copy link
Contributor

@bors bors commented on d8ab2f8 Nov 7, 2014

Choose a reason for hiding this comment

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

merging SimonSapin/rust/safer-enumset = d8ab2f8 into auto

@bors
Copy link
Contributor

@bors bors commented on d8ab2f8 Nov 7, 2014

Choose a reason for hiding this comment

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

SimonSapin/rust/safer-enumset = d8ab2f8 merged ok, testing candidate = 223ca76

@bors
Copy link
Contributor

@bors bors commented on d8ab2f8 Nov 7, 2014

Choose a reason for hiding this comment

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

@bors
Copy link
Contributor

@bors bors commented on d8ab2f8 Nov 7, 2014

Choose a reason for hiding this comment

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

fast-forwarding master to auto = 223ca76

Please sign in to comment.