4 ms·
Yeah, 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.
by Manishearth 11y ago
Yeah, 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.