4 ms·
He mentions a plug-in API in the second linked post. Enums would be a good solution, but they can't be extended with more cases by a plug-in.
by panic 11y ago
He mentions a plug-in API in the second linked post. Enums would be a good solution, but they can't be extended with more cases by a plug-in.
- Manishearth 11y agoYeah, that's when you would use trait objects in Rust (and virtual dispatch protocols in Swift?), but you still probably won't use them exactly the same way.
- alexjarvis 11y agoextensions let you do this with enums (as well as protocols): enum Car { case Red case Blue } extension Car { func hello() { print("hello") } } let x = Car.Blue x.hello() https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Protocols.html https://developer.apple.com/library/ios/documentation/Swift/... edit: although you can't add a new case to the enum.
- Manishearth 11y ago> although you can't add a new case to the enum. That's the point. We all know you can add impls or extensions.