-
-
Notifications
You must be signed in to change notification settings - Fork 74
Unify ProtocolObject and AnyObject? #843
Copy link
Copy link
Open
Labels
A-objc2Affects the `objc2`, `objc2-exception-helper` and/or `objc2-encode` cratesAffects the `objc2`, `objc2-exception-helper` and/or `objc2-encode` cratesenhancementNew feature or requestNew feature or request
Description
Metadata
Metadata
Assignees
Labels
A-objc2Affects the `objc2`, `objc2-exception-helper` and/or `objc2-encode` cratesAffects the `objc2`, `objc2-exception-helper` and/or `objc2-encode` cratesenhancementNew feature or requestNew feature or request
In Objective-C,
&AnyObjectis written asidand&ProtocolObject<dyn NSCoding>is written asid<NSCoding>; this is not a coincidence, the protocol restricts what types are allowed, but otherwise it behaves in the same way (it's essentially a bound).Maybe it would make sense to merge these? Something like:
(And at this point, possibly rename
AnyObjectback toObject?)This also feels more natural when considering multi-protocol bounds once we can support that. E.g.
Object-> no bound,Object<dyn NSCoding>-> bound toNSCoding,Object<dyn NSObjectProtocol + NSCoding>-> bound to bothNSObjectProtocolandNSCoding.This would also allow expressing "any thread-safe object" with
AnyObject<dyn Any + Send + Sync>, which is kinda nice.Anyis also actually the right tool for the job, since its requirements are'static, which is exactly also the requirement for converting&Tto&AnyObject.Probably replaces #686.