diff --git a/src/sdl2_mixer/flag.rs b/src/sdl2_mixer/flag.rs deleted file mode 100644 index 4b573574..00000000 --- a/src/sdl2_mixer/flag.rs +++ /dev/null @@ -1,109 +0,0 @@ -// Loosely based on zlib-licensed code from RustAllegro -// https://github.com/SiegeLord/RustAllegro -// -// Implements efficient, type-safe flags with support for bitwise operators. -// -// Usage: -// -// flag_type!(FlagTypeName { -// FlagName1 = FlagValue1, -// FlagName2 = FlagValue2, -// ... -// FlagNameN = FlagValueN -// }) -// -// fn foo(flag: FlagTypeName) { -// let raw = (flag | FlagNameN).get(); -// bar(raw); -// } - -#![macro_escape] - -macro_rules! flag_type( - ($typename:ident : $supertype:ident { $($name:ident = $value:expr),* }) => { - pub struct $typename { - bits: $supertype - } - - impl $typename { - #[inline] - pub fn new(bits: $supertype) -> $typename { - $typename { bits: bits } - } - - #[inline] - pub fn get(self) -> $supertype { - self.bits - } - } - - impl ::std::default::Default for $typename { - fn default() -> $typename { - $typename::new(0) - } - } - - impl ::std::cmp::Eq for $typename { - fn eq(&self, other: &$typename) -> bool { - self.bits == other.bits - } - } - - impl ::std::cmp::TotalEq for $typename {} - - impl ::std::cmp::Ord for $typename { - fn lt(&self, other: &$typename) -> bool { - self.bits < other.bits - } - } - - impl ::std::cmp::TotalOrd for $typename { - fn cmp(&self, other: &$typename) -> Ordering { - self.bits.cmp(&other.bits) - } - } - - impl ::std::ops::Not<$typename> for $typename { - fn not(&self) -> $typename { - $typename { bits: !self.bits } - } - } - - impl ::std::ops::BitAnd<$typename, $typename> for $typename { - fn bitand(&self, rhs: &$typename) -> $typename { - $typename { bits: self.bits & rhs.bits } - } - } - - impl ::std::ops::BitOr<$typename, $typename> for $typename { - fn bitor(&self, rhs: &$typename) -> $typename { - $typename { bits: self.bits | rhs.bits } - } - } - - impl ::std::ops::BitXor<$typename, $typename> for $typename { - fn bitxor(&self, rhs: &$typename) -> $typename { - $typename { bits: self.bits ^ rhs.bits } - } - } - - impl ::std::ops::Shl<$supertype, $typename> for $typename { - fn shl(&self, rhs: &$supertype) -> $typename { - $typename { bits: self.bits << *rhs } - } - } - - impl ::std::ops::Shr<$supertype, $typename> for $typename { - fn shr(&self, rhs: &$supertype) -> $typename { - $typename { bits: self.bits >> *rhs } - } - } - - $( - pub static $name: $typename = $typename { bits: $value as $supertype }; - )+ - }; - ($typename:ident { $($name:ident = $value:expr),* }) => { - flag_type!($typename : u32 { $($name = $value),* }) - } -) diff --git a/src/sdl2_mixer/lib.rs b/src/sdl2_mixer/lib.rs index 501626ef..9e173048 100644 --- a/src/sdl2_mixer/lib.rs +++ b/src/sdl2_mixer/lib.rs @@ -45,7 +45,6 @@ mod others { #[allow(non_camel_case_types, dead_code)] mod ffi; -mod flag; // This comes from SDL_audio.h #[allow(non_camel_case_types)] @@ -110,20 +109,22 @@ pub fn get_linked_version() -> Version { } } -flag_type!(InitFlag : c_int { - InitFlac = ffi::MIX_INIT_FLAC, - InitMod = ffi::MIX_INIT_MOD, - InitModPlug = ffi::MIX_INIT_MODPLUG, - InitMp3 = ffi::MIX_INIT_MP3, - InitOgg = ffi::MIX_INIT_OGG, - InitFluidSynth = ffi::MIX_INIT_FLUIDSYNTH +bitflags!(flags InitFlag : u32 { + static InitFlac = ffi::MIX_INIT_FLAC as u32, + static InitMod = ffi::MIX_INIT_MOD as u32, + static InitModPlug = ffi::MIX_INIT_MODPLUG as u32, + static InitMp3 = ffi::MIX_INIT_MP3 as u32, + static InitOgg = ffi::MIX_INIT_OGG as u32, + static InitFluidSynth = ffi::MIX_INIT_FLUIDSYNTH as u32 }) /// Loads dynamic libraries and prepares them for use. Flags should be /// one or more flags from InitFlag. pub fn init(flags: InitFlag) -> InitFlag { - let ret = unsafe { ffi::Mix_Init(flags.get()) }; - InitFlag::new(ret) + unsafe { + let ret = ffi::Mix_Init(flags.bits() as c_int); + InitFlag::from_bits(ret as u32) + } } /// Cleans up all dynamically loaded library handles, freeing memory.