Skip to content

Conversation

@MarijnS95
Copy link
Member

Searching for pub type reveals a lot of typedefs for enums that could have been a newtype with associated constants. Unfortunately there are still a lot of private enums in the source, some with a typedef following: these cannot be converted yet, otherwise we might have gotten away with globally enabling --default-enum-style to apply this style to every enum.

At the same time certain enums could use --bitfield-enum yet those eligible also suffer from the same lack of a type, requiring the user to work with _bindgen_ty_XX which is far from ergonomic.

@MarijnS95 MarijnS95 force-pushed the ndk-sys-newtype-enum branch 2 times, most recently from a7188e4 to 628bc8c Compare July 8, 2022 12:42
impl HardwareBufferUsage {
pub const CPU_READ_NEVER: Self =
Self(ffi::AHardwareBuffer_UsageFlags_AHARDWAREBUFFER_USAGE_CPU_READ_NEVER);
Self(ffi::AHardwareBuffer_UsageFlags::AHARDWAREBUFFER_USAGE_CPU_READ_NEVER);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not very sure about this anymore: would have been great to use pub type HardwareBufferUsage = ffi::AHardwareBuffer_UsageFlags; (or pub use ffi::AHardwareBuffer_UsageFlags as HardwareBufferUsage; which allows HardwareBufferUsage to be used as a constructor!) but bindgen doesn't strip duplicate naming out of variants making such a reuse very unfriendly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rust-lang/rust-bindgen#777 Unfortunately this has gotten stale on the bindgen side :/

@MarijnS95 MarijnS95 force-pushed the ndk-sys-newtype-enum branch from 628bc8c to 697b9cb Compare July 8, 2022 12:46
@MarijnS95 MarijnS95 changed the title ndk-sys: Switch remaining enums to newtypes with associated constant ndk-sys: Switch remaining enums to newtypes with associated constants Jul 8, 2022
@MarijnS95 MarijnS95 force-pushed the ndk-sys-newtype-enum branch 2 times, most recently from c64b23f to 3ed2434 Compare July 8, 2022 13:27
};
construct(|res| unsafe {
ffi::AHardwareBuffer_lock(self.as_ptr(), usage.0, fence, rect, res)
ffi::AHardwareBuffer_lock(self.as_ptr(), usage.0 .0, fence, rect, res)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these spaces between the .0s look a bit weird to me, was this intentional as cargo fmt doesnt seem to complain?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@msiglreith It was actually cargo fmt that did this, perhaps to prevent some possible mis-interpretation of 0.0?

We run cargo fmt in the CI and it's green, so it doesn't complain :)

Searching for `pub type` reveals a lot of typedefs for enums that could
have been a newtype with associated constants.  Unfortunately there are
still a lot of private enums in the source, some with a `typedef`
following: these cannot be converted yet, otherwise we might have gotten
away with globally enabling `--default-enum-style` to apply this style
to _every_ enum.

At the same time certain enums could use `--bitfield-enum` yet those
eligible also suffer from the same lack of a type, requiring the user to
work with `_bindgen_ty_XX` which is far from ergonomic.
@MarijnS95 MarijnS95 force-pushed the ndk-sys-newtype-enum branch from 3ed2434 to d5a7fe6 Compare July 12, 2022 12:22
@MarijnS95 MarijnS95 merged commit 6acbe17 into master Jul 15, 2022
@MarijnS95 MarijnS95 deleted the ndk-sys-newtype-enum branch July 15, 2022 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants