Conversation
|
A somewhat end-goal is that we can use this in ProtocolObject<dyn NSMutableCopying + NSFastEnumeration>
// where:
// trait NSMutableCopying: NSCopying { ... }
// trait NSFastEnumeration { ... }To use such an object, we would like the following implementations to exist: // Required to use the object at all
impl NSCopying for ProtocolObject<dyn NSMutableCopying + NSFastEnumeration> {}
impl NSMutableCopying for ProtocolObject<dyn NSMutableCopying + NSFastEnumeration> {}
impl NSFastEnumeration for ProtocolObject<dyn NSMutableCopying + NSFastEnumeration> {}
// Would be nice to have
impl ConformsTo<dyn NSCopying> for ProtocolObject<dyn NSMutableCopying + NSFastEnumeration> {}
impl ConformsTo<dyn NSMutableCopying> for ProtocolObject<dyn NSMutableCopying + NSFastEnumeration> {}
impl ConformsTo<dyn NSFastEnumeration> for ProtocolObject<dyn NSMutableCopying + NSFastEnumeration> {}
// Not really that important, but could be cool
impl ConformsTo<dyn NSCopying + NSFastEnumeration> for ProtocolObject<dyn NSMutableCopying + NSFastEnumeration> {}
impl ConformsTo<dyn NSMutableCopying + NSFastEnumeration> for ProtocolObject<dyn NSMutableCopying + NSFastEnumeration> {}// For an object `MyClass` that implements the protocols, these are required
impl NSCopying for MyClass {}
impl NSMutableCopying for MyClass {}
impl NSFastEnumeration for MyClass {}
// And these would be expected
impl ConformsTo<dyn NSCopying> for MyClass {}
impl ConformsTo<dyn NSMutableCopying> for MyClass {}
impl ConformsTo<dyn NSFastEnumeration> for MyClass {}
// To properly handle the case above, these would be nice
impl ConformsTo<dyn NSCopying + NSFastEnumeration> for MyClass {}
impl ConformsTo<dyn NSMutableCopying + NSFastEnumeration> for MyClass {}Note: |
|
I've been going about this a bit wrong; what we want is for users to specify this: extern_protocol!(
unsafe trait NSCopying {
// ...
}
);
extern_protocol!(
unsafe trait NSMutableCopying: NSCopying {
// ...
}
);
extern_protocol!(
unsafe trait NSFastEnumeration {
// ...
}
);
extern_class!(
struct MyClass;
);
unsafe impl NSCopying for MyClass {}
unsafe impl NSMutableCopying for MyClass {}
unsafe impl NSFastEnumeration for MyClass {}Notice how the protocol implementations for the class is not in the Additionally, the use of |
|
Implementation-wise: extern_protocol!(
unsafe trait FooBar: Foo + Bar {}
);
// Generates
unsafe trait FooBar: ... {...}
unsafe impl<T: ?Sized + FooBar> FooBar for ProtocolObject<T> {}
// Note: Needs to be done a bit differently because of the orphan rule
impl<T: ?Sized + FooBar> ConformsTo<dyn FooBar> for T {}
// Maybe?
// impl<T: ?Sized + FooBar> ConformsTo<dyn Foo> for T {}
// impl<T: ?Sized + FooBar> ConformsTo<dyn Bar> for T {} |
f604a71 to
d1d1a2d
Compare
d1d1a2d to
1d4c24d
Compare
b0ed481 to
f0ab916
Compare
f0ab916 to
cf15592
Compare
cb25ea0 to
6b9179e
Compare
Fixes #291.
TODO:
Use new implementation forDeferred to FixNSCopying,NSMutableCopying, ...NSCopyingandNSMutableCopying#401dynlike this doesn't incur extra overhead