-
Notifications
You must be signed in to change notification settings - Fork 40
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
Proof of concept for proc macros #413
Conversation
// string: &NSString, | ||
// ) -> Id<Self, Shared>; | ||
// | ||
// #[method(sel = loadHTMLString:baseURL:, retain)] // retain without = defaults to `other` |
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.
We could probably make specifying even retain
optional in the typical case since we could just determine this by looking at the return type of the signature.
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.
The reason that I did it the @__retain_semantics
extern_methods!
originally is because of performance (otherwise it uses const
stuff to figure out the retain method from the selector), but doing such work is possibly performant enough when running as a proc macro, so we might not need it at all.
|
||
// Examples: | ||
// | ||
// #[method(sel = initTextCell:, retain = 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.
Similar to my other comment, we could allow eliding the retain info here as well (by examining the type of this
).
Thinking about this some more, it seems like we might be able to simplify things more than I anticipated. What if we had something like this: #[class(extern, super = NSActionCell, inherits = NSCell, NSObject)]
struct NSPathCell;
// `unsafe impl ClassType for NSPathCell` added automatically
#[class]
unsafe impl NSPathCell {
// #[method] can often be skipped entirely
pub unsafe fn pathStyle(&self) -> NSPathStyle;
pub unsafe fn setPathStyle(&self, path_style: NSPathStyle);
#[cfg(all(feature = "Foundation_NSArray", feature = "Foundation_NSString"))]
pub unsafe fn allowedTypes(&self) -> Option<Id<NSArray<NSString>, Shared>>;
}
#[protocol] // `: NSObjectProtocol` can be added automatically
pub unsafe trait NSPathCellDelegate {
#[cfg(all(feature = "AppKit_NSOpenPanel", feature = "AppKit_NSPathCell"))]
#[method(optional)] // selector computed from name
unsafe fn pathCell_willDisplayOpenPanel(
&self,
path_cell: &NSPathCell,
open_panel: &NSOpenPanel,
);
}
// `unsafe impl ProtocolType for dyn NSPathCellDelegate {}` added automatically Anyway, I might try experimenting with a few different approaches to see what seems feasible. |
Don't spend too much time on this; we'll want different names for methods anyhow: #284
I'm not sure about this one, it would allow writing something like |
Also, I suspect I'd like to keep |
Superseded by #425 |
Following the discussion from #411