-
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
Improving how we map protocols #291
Comments
Further idea generation: trait ProtocolType {}
// TODO: Better name
struct Helper<P: ProtocolType> {
__inner: Object,
p: PhantomData<P>,
}
trait ConformsTo<P: ProtocolType> {
fn as_protocol(&self) -> &Helper<P>;
fn as_protocol_mut(&mut self) -> &mut Helper<P>;
}
// NSLocking.rs
trait NSLocking: Message {
unsafe fn lock(&self) {
msg_send![self, lock]
}
unsafe fn unlock(&self) {
msg_send![self, unlock]
}
}
impl ProtocolType for dyn NSLocking {}
impl NSLocking for Helper<dyn NSLocking> {}
// NSLock.rs
declare_class!(NSLock ...);
impl NSLocking for NSLock {}
impl ConformsTo<dyn NSLocking> for NSLock {}
// NSSecureCoding.rs
trait NSSecureCoding: Message {
fn supportsSecureCoding_class() -> bool
where
Self: ClassType
{
msg_send![Self::class(), supportsSecureCoding]
}
}
impl ProtocolType for dyn NSSecureCoding {}
impl NSSecureCoding for Helper<dyn NSSecureCoding> {}
// NSTextCheckingClient.rs
trait NSTextCheckingClient: NSTextInputClient + NSTextInputTraits { ... } Usage:
|
What's the current state of extern_protocol!(
struct ASAuthorizationControllerDelegateObject;
unsafe impl ProtocolType for ASAuthorizationControllerDelegateObject {
const NAME: &'static str = "ASAuthorizationControllerDelegate";
#[method(attestationController:controller:digCompelteWithAuthorization:)]
unsafe fn authorization_controller_did_complete_with_authorization(
&self,
_controller: &ASAuthorizationController,
authorization: &ASAuthorization,
);
}
); and I'm getting
|
The issue seems to be that you've specified the wrong selector? See also how it's used in |
Oh sorry you're totally right. That'll teach meto write this stuff that late at night... |
#321 should fix the error message ;) |
Continuing on the work done in #250.
Currently
A protocol is mapped to a struct that impls
Message
, which allows using it inId
.This allows similar patterns as
id<ProtocolName>
would do in Objective-C, but has a lot of tradeoffs, including:Calling a method on a protocol is more cumbersome than doing it on a normal struct.
Protocol class methods are impossible to do
Calling methods on protocols that has multiple parent protocols is cumbersome:
Ideally
Ideally the constraints outlined above would be gone
Idea
Maybe we could use something like
Newtype<dyn MyProtocol>
in place of&MyProtocol
(since we can't override the behaviour of&dyn MyProtocol
)? And do specialized stuff inId
to handleId<dyn MyProtocol>
?The text was updated successfully, but these errors were encountered: