Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Implement NSWindowStyleMask as bitflags #160

Merged
merged 4 commits into from Mar 22, 2017
Merged

Implement NSWindowStyleMask as bitflags #160

merged 4 commits into from Mar 22, 2017

Conversation

oluseyi
Copy link
Contributor

@oluseyi oluseyi commented Mar 22, 2017

RE #159

NSWindowStyleMask, as an enumeration in Objective-C, degrades to NSUInteger and is therefore bitwise-combinable, though it loses type information. Instead of implementing NSWindowStyleMask as a packed-data object with a u64 representational form, we ought to employ bit flags to generate a strong type that remains combinable in the manner Cocoa programmers are accustomed to. Also easier than manually implementing std::ops::BitOr for the type.


This change is Reviewable

…r and is therefore bitwise-combinable, though it loses type information. Instead of implementing NSWindowMask as a packed-data object with a u64 representational form, we ought to employ bit flags to generate a strong type that remains combinable in the manner Cocoa programmers are accustomed to. Also easier than manually implementing std::ops::BitOr for the type.
src/appkit.rs Outdated
msg_send![self, styleMask]
unsafe fn styleMask(self) -> NSWindowMask {
let styleMask = msg_send![self, styleMask];
styleMask
Copy link
Member

Choose a reason for hiding this comment

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

I'm surprised that this works as written. Doesn't this need to call NSWindowMask::from_bits or from_bits_truncate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

from_bits_truncate would add a nice validity check. I'll add that in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Also renamed NSWindowMask to NSWindowStyleMask to match AppKit.

…nd maps to declared fields. Prefer truncate because macOS may use reserved bits for private purposes, or introduce new values in future versions.
@jdm
Copy link
Member

jdm commented Mar 22, 2017

@bors-servo: r+

@bors-servo
Copy link

📌 Commit 135fce2 has been approved by jdm

@bors-servo
Copy link

⌛ Testing commit 135fce2 with merge 31d8ba2...

bors-servo pushed a commit that referenced this pull request Mar 22, 2017
Implement NSWindowStyleMask as bitflags

RE #159

`NSWindowStyleMask`, as an enumeration in Objective-C, degrades to `NSUInteger` and is therefore bitwise-combinable, though it loses type information. Instead of implementing `NSWindowStyleMask` as a packed-data object with a `u64` representational form, we ought to employ bit flags to generate a strong type that remains combinable in the manner Cocoa programmers are accustomed to. Also easier than manually implementing `std::ops::BitOr` for the type.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/cocoa-rs/160)
<!-- Reviewable:end -->
@bors-servo
Copy link

💔 Test failed - status-travis

@jdm
Copy link
Member

jdm commented Mar 22, 2017

Example needs to be updated now:

error[E0308]: mismatched types

  --> examples/hello_world.rs:40:59

   |

40 |                                                           NSTitledWindowMask as NSUInteger,

   |                                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `cocoa::appkit::NSWindowStyleMask`, found u64

   |

   = note: expected type `cocoa::appkit::NSWindowStyleMask`

              found type `u64`

error: non-scalar cast: `cocoa::appkit::NSWindowStyleMask` as `u64`

  --> examples/hello_world.rs:40:59

   |

40 |                                                           NSTitledWindowMask as NSUInteger,

   |                                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

error: Could not compile `cocoa`.

@oluseyi
Copy link
Contributor Author

oluseyi commented Mar 22, 2017

Yeah, saw the message from bors-servo. Was at lunch; committing now. Thanks @jdm.

@jdm
Copy link
Member

jdm commented Mar 22, 2017

@bors-servo: r+

@bors-servo
Copy link

📌 Commit e773703 has been approved by jdm

@bors-servo
Copy link

⌛ Testing commit e773703 with merge 4c63ce7...

bors-servo pushed a commit that referenced this pull request Mar 22, 2017
Implement NSWindowStyleMask as bitflags

RE #159

`NSWindowStyleMask`, as an enumeration in Objective-C, degrades to `NSUInteger` and is therefore bitwise-combinable, though it loses type information. Instead of implementing `NSWindowStyleMask` as a packed-data object with a `u64` representational form, we ought to employ bit flags to generate a strong type that remains combinable in the manner Cocoa programmers are accustomed to. Also easier than manually implementing `std::ops::BitOr` for the type.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/cocoa-rs/160)
<!-- Reviewable:end -->
@bors-servo
Copy link

☀️ Test successful - status-travis
Approved by: jdm
Pushing 4c63ce7 to master...

@bors-servo bors-servo merged commit e773703 into servo:master Mar 22, 2017
@oluseyi oluseyi deleted the bitflag-window-masks branch March 22, 2017 18:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants