Add webkit example#360
Conversation
|
EDIT: I think I figured out most of the issues I mentioned (but feedback still welcome) |
madsmtm
left a comment
There was a problem hiding this comment.
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 |
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 ;) |
| 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.
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.