[swift-evolution] [Pitch] Non-class type requirements on protocols (eg : struct, : enum)

Xiaodi Wu xiaodi.wu at gmail.com
Fri Oct 21 01:54:23 CDT 2016


What's your use case for distinguishing structs and enums?
On Fri, Oct 21, 2016 at 1:40 AM Mike Kasianowicz via swift-evolution <
swift-evolution at swift.org> wrote:

> Currently protocols can have the class constraint:
> protocol MyProtocol : class {}
>
> It would be (a) intuitive and (b) useful to allow such things as:
> protocol Model : struct {} or protocol Event : enum {}
>
> These types of restrictions can help prevent accidental anti-patterns or
> misuse of APIs.
>
> Seems simple and non-controversial... right?
>
> [Note: I'd like to see even more heavy-handed protocol restrictions in the
> future.  For example, a protocol describing an enum with a common case, or
> a struct with no reference members. Great stuff for defensively coding
> APIs.]
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161021/f672170f/attachment.html>


More information about the swift-evolution mailing list