Skip to content

Add other bitwise ops for bitflag enums #698

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

Merged
merged 1 commit into from
May 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2009,8 +2009,43 @@ impl<'a> EnumBuilder<'a> {
}
)
.unwrap();
result.push(impl_);

let impl_ = quote_item!(ctx.ext_cx(),
impl ::$prefix::ops::BitOrAssign for $rust_ty {
#[inline]
fn bitor_assign(&mut self, rhs: $rust_ty) {
self.0 |= rhs.0;
}
}
)
.unwrap();
result.push(impl_);

let impl_ = quote_item!(ctx.ext_cx(),
impl ::$prefix::ops::BitAnd<$rust_ty> for $rust_ty {
type Output = Self;

#[inline]
fn bitand(self, other: Self) -> Self {
$rust_ty_name(self.0 & other.0)
}
}
)
.unwrap();
result.push(impl_);

let impl_ = quote_item!(ctx.ext_cx(),
impl ::$prefix::ops::BitAndAssign for $rust_ty {
#[inline]
fn bitand_assign(&mut self, rhs: $rust_ty) {
self.0 &= rhs.0;
}
}
)
.unwrap();
result.push(impl_);

aster
}
EnumBuilder::Consts { aster, .. } => aster,
Expand Down
66 changes: 66 additions & 0 deletions tests/expectations/tests/bitfield-enum-basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ impl ::std::ops::BitOr<Foo> for Foo {
#[inline]
fn bitor(self, other: Self) -> Self { Foo(self.0 | other.0) }
}
impl ::std::ops::BitOrAssign for Foo {
#[inline]
fn bitor_assign(&mut self, rhs: Foo) { self.0 |= rhs.0; }
}
impl ::std::ops::BitAnd<Foo> for Foo {
type
Output
=
Self;
#[inline]
fn bitand(self, other: Self) -> Self { Foo(self.0 & other.0) }
}
impl ::std::ops::BitAndAssign for Foo {
#[inline]
fn bitand_assign(&mut self, rhs: Foo) { self.0 &= rhs.0; }
}
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct Foo(pub ::std::os::raw::c_int);
Expand All @@ -31,6 +47,22 @@ impl ::std::ops::BitOr<Buz> for Buz {
#[inline]
fn bitor(self, other: Self) -> Self { Buz(self.0 | other.0) }
}
impl ::std::ops::BitOrAssign for Buz {
#[inline]
fn bitor_assign(&mut self, rhs: Buz) { self.0 |= rhs.0; }
}
impl ::std::ops::BitAnd<Buz> for Buz {
type
Output
=
Self;
#[inline]
fn bitand(self, other: Self) -> Self { Buz(self.0 & other.0) }
}
impl ::std::ops::BitAndAssign for Buz {
#[inline]
fn bitand_assign(&mut self, rhs: Buz) { self.0 &= rhs.0; }
}
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct Buz(pub ::std::os::raw::c_schar);
Expand All @@ -44,6 +76,22 @@ impl ::std::ops::BitOr<_bindgen_ty_1> for _bindgen_ty_1 {
#[inline]
fn bitor(self, other: Self) -> Self { _bindgen_ty_1(self.0 | other.0) }
}
impl ::std::ops::BitOrAssign for _bindgen_ty_1 {
#[inline]
fn bitor_assign(&mut self, rhs: _bindgen_ty_1) { self.0 |= rhs.0; }
}
impl ::std::ops::BitAnd<_bindgen_ty_1> for _bindgen_ty_1 {
type
Output
=
Self;
#[inline]
fn bitand(self, other: Self) -> Self { _bindgen_ty_1(self.0 & other.0) }
}
impl ::std::ops::BitAndAssign for _bindgen_ty_1 {
#[inline]
fn bitand_assign(&mut self, rhs: _bindgen_ty_1) { self.0 &= rhs.0; }
}
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct _bindgen_ty_1(pub ::std::os::raw::c_uint);
Expand All @@ -64,6 +112,24 @@ impl ::std::ops::BitOr<Dummy__bindgen_ty_1> for Dummy__bindgen_ty_1 {
Dummy__bindgen_ty_1(self.0 | other.0)
}
}
impl ::std::ops::BitOrAssign for Dummy__bindgen_ty_1 {
#[inline]
fn bitor_assign(&mut self, rhs: Dummy__bindgen_ty_1) { self.0 |= rhs.0; }
}
impl ::std::ops::BitAnd<Dummy__bindgen_ty_1> for Dummy__bindgen_ty_1 {
type
Output
=
Self;
#[inline]
fn bitand(self, other: Self) -> Self {
Dummy__bindgen_ty_1(self.0 & other.0)
}
}
impl ::std::ops::BitAndAssign for Dummy__bindgen_ty_1 {
#[inline]
fn bitand_assign(&mut self, rhs: Dummy__bindgen_ty_1) { self.0 &= rhs.0; }
}
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct Dummy__bindgen_ty_1(pub ::std::os::raw::c_uint);
Expand Down