Skip to content
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

Implement NSWindowStyleMask as bitflags #160

Merged
merged 4 commits into from Mar 22, 2017

Conversation

@oluseyi
Copy link
Contributor

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.
msg_send![self, styleMask]
unsafe fn styleMask(self) -> NSWindowMask {
let styleMask = msg_send![self, styleMask];
styleMask

This comment has been minimized.

Copy link
@jdm

jdm Mar 22, 2017

Member

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

This comment has been minimized.

Copy link
@oluseyi

oluseyi Mar 22, 2017

Author Contributor

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

This comment has been minimized.

Copy link
@oluseyi

oluseyi Mar 22, 2017

Author Contributor

Done. Also renamed NSWindowMask to NSWindowStyleMask to match AppKit.

oluseyi added 2 commits Mar 22, 2017
…nd maps to declared fields. Prefer truncate because macOS may use reserved bits for private purposes, or introduce new values in future versions.
@jdm

This comment has been minimized.

Copy link
Member

jdm commented Mar 22, 2017

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo commented Mar 22, 2017

📌 Commit 135fce2 has been approved by jdm

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo commented Mar 22, 2017

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

bors-servo added 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

This comment has been minimized.

Copy link
Contributor

bors-servo commented Mar 22, 2017

💔 Test failed - status-travis

@jdm

This comment has been minimized.

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

This comment has been minimized.

Copy link
Contributor Author

oluseyi commented Mar 22, 2017

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

@jdm

This comment has been minimized.

Copy link
Member

jdm commented Mar 22, 2017

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo commented Mar 22, 2017

📌 Commit e773703 has been approved by jdm

@bors-servo

This comment has been minimized.

Copy link
Contributor

bors-servo commented Mar 22, 2017

⌛️ Testing commit e773703 with merge 4c63ce7...

bors-servo added 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

This comment has been minimized.

Copy link
Contributor

bors-servo commented Mar 22, 2017

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

@bors-servo bors-servo merged commit e773703 into servo:master Mar 22, 2017
1 check passed
1 check passed
homu Test successful
Details
@oluseyi oluseyi deleted the oluseyi:bitflag-window-masks branch Mar 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.