You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been playing around with the generated bindings for UIKit and have noticed a point of friction that I think we could alleviate with bindgen but want to get some feedback before I implement it.
There's a lot of other stuff generated but this is the change I'm suggesting.
pubstructBar(pubid);// This is the same as above. It's here to clarify BarpubtraitIFoo:Sized + std::ops::Deref{unsafefnmethodUsingBar_(self,my_bar:Bar)where
<Selfas std::ops::Deref>::Target: objc::Message + Sized,{msg_send!(self, methodUsingBar:*my_bar)}unsafefnmethodReturningBar() -> Barwhere
<Selfas std::ops::Deref>::Target: objc::Message + Sized,{Bar(msg_send!(class!(Foo), methodReturningBar))}}
In case it's not clear as to why this is useful, I'll provide an example. In my case, I've got some uikit-sys bindings and want to create a UILabel and give it a boarder. With the current bindings you do the following:;
let label = UILabel::alloc();
label.init();// label.layer() returns a CALayer*// https://developer.apple.com/documentation/uikit/uiview/1622436-layer?language=objclet layer = CALayer(label.layer());
layer.setBorderWidth_(3.0);
If we (probably me) adds this feature we will have something more like:
let label = UILabel::alloc();
label.init();// layer is of type CALayerlet layer = label.layer();
layer.setBorderWidth_(3.0);
This might seem like a small reduction in code but the area to where it's very useful is type checking. Given the message passing nature of objective-c, you could create CALayer with any Objective-c id and the bindings that are currently generated will accept this at compile time. Adding a generated wrapper around the objective-c id's will add better checking as well as the user of bindings will have a much easier time navigating the creation and usage of these bindings because return of functions will actually inform the user of the rust side types and would auto link to that types documentation.
Thoughts?
The text was updated successfully, but these errors were encountered:
simlay
changed the title
Use Objective-C Bindgen names in Object-C pointer return types.
Use Objective-C Bindgen names in Object-C pointer input and return types.
Jul 25, 2020
simlay
changed the title
Use Objective-C Bindgen names in Object-C pointer input and return types.
Use Bindgen names in Object-C pointer input and return types.
Jul 25, 2020
Uh oh!
There was an error while loading. Please reload this page.
I've been playing around with the generated bindings for UIKit and have noticed a point of friction that I think we could alleviate with bindgen but want to get some feedback before I implement it.
Input ObjC Header
Bindgen Invocation
Actual Results
The part of this generated binding that's relevant to this ticket is:
Expected Results
There's a lot of other stuff generated but this is the change I'm suggesting.
In case it's not clear as to why this is useful, I'll provide an example. In my case, I've got some uikit-sys bindings and want to create a UILabel and give it a boarder. With the current bindings you do the following:;
If we (probably me) adds this feature we will have something more like:
This might seem like a small reduction in code but the area to where it's very useful is type checking. Given the message passing nature of objective-c, you could create
CALayer
with any Objective-c id and the bindings that are currently generated will accept this at compile time. Adding a generated wrapper around the objective-c id's will add better checking as well as the user of bindings will have a much easier time navigating the creation and usage of these bindings because return of functions will actually inform the user of the rust side types and would auto link to that types documentation.Thoughts?
The text was updated successfully, but these errors were encountered: