Yes your right. To be useful in bitwise operation you need four methods I think
 fn pub or_enum() -> uint
 fn pub add_all(&[CLike]) or
 fn pub to_array() -> ~[CLike]
 fn pub add_unfold(uint)

No sure with the names but if the idea to add some methods is validated I can try to implements them.

Philippe


Le 16/01/2014 00:30, John Grosen a écrit :
EnumSet (http://static.rust-lang.org/doc/master/extra/enum_set/struct.EnumSet.html) looks almost exactly like what you want --- except, unfortunately, it doesn't actually expose its `bits` field. Perhaps a new method should be added to it?

--
John Grosen

On Wednesday, January 15, 2014 at 3:24 PM, Jan Niklas Hasse wrote:

On Wed, Jan 15, 2014, at 08:45 AM, Philippe Delrieu wrote:
Thanks for you answer . I have the idea to see in the SDL port (I work
on the SDL2 port) which is finished and has the same problems. They
solve the problem like this :

pub fn unfold_bits(bitflags: u32) -> ~[SDL_WindowFlags] {
let flags = [SDL_WINDOW_FULLSCREEN,
SDL_WINDOW_OPENGL,
SDL_WINDOW_SHOWN,
SDL_WINDOW_HIDDEN,
SDL_WINDOW_BORDERLESS,
SDL_WINDOW_RESIZABLE,
SDL_WINDOW_MINIMIZED,
SDL_WINDOW_MAXIMIZED,
SDL_WINDOW_INPUT_GRABBED,
SDL_WINDOW_INPUT_FOCUS,
SDL_WINDOW_MOUSE_FOCUS,
SDL_WINDOW_FULLSCREEN_DESKTOP,
SDL_WINDOW_FOREIGN
];

flags.iter().filter_map(|&flag| {
if bitflags & (flag as u32) != 0 { Some(flag) }
else { None }
}).collect()
}

Philippe

Le 15/01/2014 17:36, SiegeLord a écrit :
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
_______________________________________________
Rust-dev mailing list
[email protected] <mailto:[email protected]>
https://mail.mozilla.org/listinfo/rust-dev

_______________________________________________
Rust-dev mailing list
[email protected] <mailto:[email protected]>
https://mail.mozilla.org/listinfo/rust-dev

Did you know that there are SDL2 bindings for Rust?

See:
https://github.com/AngryLawyer/rust-sdl2/blob/master/src/sdl2/video.rs
_______________________________________________
Rust-dev mailing list
[email protected] <mailto:[email protected]>
https://mail.mozilla.org/listinfo/rust-dev



_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to