I’ve been aching for this feature for what feels like ages! My main use case is an event-driven UI (and not only UI) architecture:
public protocol InputEventHandler {
associatedtype InputEvent
func handle(_ event: InputEvent)
}
public protocol CanCloseInputEvent {
static var close: Self { get }
}
public protocol CanMinimizeInputEvent {
static var minimize: Self { get }
}
public func doSomethingWith<W>(window: W) where W: InputEventHandler, W.Event: CanCloseInputEvent & CanMinimizeInputEvent {
// ...
}
struct MyWindow: InputEventHandler {
enum InputEvent: CanCloseInputEvent, CanMinimizeInputEvent {
case close
case minimize
}
func handle(_ event: InputEvent) {
// ...
}
}