Fixed up some of the code for c_enums and c_flags. Also added examples.

This commit is contained in:
Jason Smith
2017-08-24 14:02:53 -04:00
parent 8b5d5a9c57
commit d408d4b239
4 changed files with 96 additions and 29 deletions

34
examples/flags.rs Normal file
View File

@ -0,0 +1,34 @@
#[macro_use]
extern crate binding;
c_flags!
{
/// A sample of flags useful for the EvDev library.
flags ReadFlags: u32
{
/// Process data in sync mode.
const SYNC = 0b000000000000000000000001,
/// Process data in normal mode.
const NORMAL = 0b000000000000000000000010,
/// Pretend the next event is a SYN_DROPPED and require
/// the caller to sync.
const FORCE_SYNC = 0b000000000000000000000100,
/// The fd is not in O_NONBLOCK and a read may block.
const BLOCKING = 0b000000000000000000001000
}
}
pub fn main()
{
let flag: ReadFlags;
flag = SYNC | NORMAL;
println!("Flag: {:#010b}", flag.get_bits());
println!("Flag: {}", flag);
}