[rust-dev] Bitwise operations in rust.

SiegeLord slabode at aim.com
Wed Jan 15 08:36:33 PST 2014


On 01/15/2014 11:29 AM, Nicolas Silva wrote:
> I think enums are not a good fit for bitwise operations, it's not really
> meant for that.
I came to the same conclusion and came up with a nice macro to automate 
that, seen here: 
https://github.com/SiegeLord/RustAllegro/blob/master/src/rust_util.rs#L3..L56 
and used here 
https://github.com/SiegeLord/RustAllegro/blob/master/src/allegro/internal/bitmap_like.rs#L9..L23 
.

This enables a nice, C-like API when composing/extracting flags via the 
bit-or and bit-and operators.

-SL


More information about the Rust-dev mailing list