-
Notifications
You must be signed in to change notification settings - Fork 44
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
Add webkit example #360
Add webkit example #360
Conversation
EDIT: I think I figured out most of the issues I mentioned (but feedback still welcome) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes please, examples are very much welcome!
One observation I had about writing the init method is that it would be nice if we could somehow use unsafe fn __init_withTextField_andWebView(self: &mut Self, text_field: *mut NSTextField, web_view: *mut WKWebView) -> Option<&mut Self> {
let this: Option<&mut Self> = msg_send![super(self), init];
this.and_then(|this| {
Id::retain(text_field).and_then(|text_field| {
Id::retain(web_view).and_then(|web_view| {
Ivar::write(&mut this.text_field, text_field);
Ivar::write(&mut this.web_view, web_view);
Some(this)
})
})
})
} The If |
You can use After #173, you would even be able to write: #[method_id(initWithTextField:andWebView:)]
unsafe fn __init_withTextField_andWebView(this: Allocated<Self>, text_field: *mut NSTextField, web_view: *mut WKWebView) -> Option<Id<Self, Owned>> {
let this = unsafe { msg_send_id![super(self), init] }?;
Ivar::write(&mut this.text_field, unsafe { Id::retain(text_field) }?);
Ivar::write(&mut this.web_view, unsafe { Id::retain(web_view) }?);
Some(this)
} Also, I have ideas for making |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very interesting. Did this change recently? I thought it used to not work (or it kind of did, but there was some problem involving |
Well, recently is subjective, but godbolt shows it worked since Rust 1.22 ;) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, thanks!
text_field: *mut NSTextField, | ||
web_view: *mut WKWebView, | ||
) -> Option<&mut Self> { | ||
let this: Option<&mut Self> = msg_send![super(self), init]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's weird, I wouldn't have expected you to be able to elide the unsafe
around this message send when we have #![deny(unsafe_op_in_unsafe_fn)]
. But that's a different issue
I created a small example using the generated WebKit bindings. If you have any ideas on how to improve the structure, feel free to make whatever changes you'd like.
I also made some feature sets for the examples so that they can be run a little easier and I added a README.