-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for #39 #51
Fix for #39 #51
Conversation
I'm not particularly attached to this if it doesn't work for some cases; but it does the job for me. |
Interesting fix! Will try in cocoa-rs. |
@dimbleby That fixes the values, but not the type of the enum. This additional patch fixes the types: diff --git i/src/lib.rs w/src/lib.rs
index d687d3f..5782cc7 100644
--- i/src/lib.rs
+++ w/src/lib.rs
@@ -231,11 +231,13 @@ macro_rules! bitflags {
// private, which prevents us from using it to define
// public constants.
pub struct $BitFlags {
- bits: $T,
+ bits: usize,
}
mod real_flags {
use super::$BitFlags;
- $($(#[$Flag_attr])* pub const $Flag: $BitFlags = $BitFlags { bits: super::super::$Flag.bits };)+
+ $($(#[$Flag_attr])* pub const $Flag: $BitFlags = $BitFlags {
+ bits: super::super::$Flag.bits as usize
+ };)+
}
// Now we define the "undefined" versions of the flags.
// This way, all the names exist, even if some are #[cfg]ed
@@ -243,7 +245,7 @@ macro_rules! bitflags {
$(const $Flag: $BitFlags = $BitFlags { bits: 0 };)+
#[inline]
- pub fn fmt(self_: $T,
+ pub fn fmt(self_: usize,
f: &mut $crate::__core::fmt::Formatter)
-> $crate::__core::fmt::Result {
// Now we import the real values for the flags.
@@ -253,7 +255,7 @@ macro_rules! bitflags {
let mut first = true;
$(
// $Flag.bits == 0 means that $Flag doesn't exist
- if $Flag.bits != 0 && self_ & $Flag.bits == $Flag.bits {
+ if $Flag.bits != 0 && self_ & $Flag.bits as usize == $Flag.bits as usize {
if !first {
try!(f.write_str(" | "));
}
@@ -264,7 +266,7 @@ macro_rules! bitflags {
Ok(())
}
}
- dummy::fmt(self.bits, f)
+ dummy::fmt(self.bits as usize, f)
}
}
@@ -283,21 +285,23 @@ macro_rules! bitflags {
#[allow(dead_code)]
mod dummy {
pub struct $BitFlags {
- bits: $T,
+ bits: usize,
}
mod real_flags {
use super::$BitFlags;
- $($(#[$Flag_attr])* pub const $Flag: $BitFlags = $BitFlags { bits: super::super::$Flag.bits };)+
+ $($(#[$Flag_attr])* pub const $Flag: $BitFlags = $BitFlags {
+ bits: super::super::$Flag.bits as usize
+ };)+
}
$(const $Flag: $BitFlags = $BitFlags { bits: 0 };)+
#[inline]
- pub fn all() -> $T {
+ pub fn all() -> usize {
use self::real_flags::*;
$($Flag.bits)|+
}
}
- $BitFlags { bits: dummy::all() }
+ $BitFlags { bits: dummy::all() as $T }
}
/// Returns the raw value of the flags currently stored. Feel free to amend your PR with this if you want. |
@nox - thanks! will do |
Wouldn't it be better to use |
@Amanieu True that! It should be |
Don't have inner modules use a type that may only be available in outer modules.
This is a useful PR. @alexcrichton Any chance of a merge and possible release? :) |
Thanks @dimbleby! |
Avoid definitions in inner modules being dependent on things that may
only be in scope in outer modules.