-
Notifications
You must be signed in to change notification settings - Fork 49
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
define_class!
: Allow safe overriding of methods / safe implementation of protocols
#437
Comments
Actually, creating news methods (i.e. not overriding) is safe (provided they are not special methods like So perhaps we need a |
Okay so we have two cases that I see a solution to:
The hardest part here is overriding methods. But checking that the signatures are equal is difficult! Possibly we could do the following check in the type system: Note that having matching method encodings is not enough to make overriding safe. |
Another option is to have traits for each implementation, that the user can then select. So e.g.: trait NSView_methods {
fn drawRect(&self, rect: NSRect);
}
// Usage
define_class!(
struct MyView;
// unsafe impl ClassType ...
impl NSView_methods for MyView {
#[method(drawRect:)]
fn drawRect(&self, rect: NSRect) {
// Do drawing
}
}
); Though this is just... Not very nice, and can be confusing to find the right trait for the methods you want (especially for |
Though maybe the idea of specifying which class' method you're overriding is not a bad one? It would allow us to get the type from |
Note that we're assuming the user uses the same method names as the superclass/protocol, which they don't necessarily have to, so we also need a way to verify that. A nice thing about that though is that we could maybe avoid the need to specify a selector in |
declare_class!
: Allow safe overriding of methods / safe implementation of protocolsdefine_class!
: Allow safe overriding of methods / safe implementation of protocols
It would be nice if
icrate
could mark certain protocols / methods as safe to override, such thatdefine_class!
could (after checking that all types are the same) allow just doing:(Notice the lack of
unsafe impl
)The text was updated successfully, but these errors were encountered: