# Constrain protocol usage outside the module

**URL:** <https://forums.swift.org/t/constrain-protocol-usage-outside-the-module/8832>\
**Category:** Pitches\
**Created:** [January 25, 2018, 9:03am UTC](https://forums.swift.org/t/constrain-protocol-usage-outside-the-module/8832 "2018-01-25T09:03:18Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

**Author:** ![hashemi](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/hashemi/32/9508_2.png) [@hashemi](https://forums.swift.org/u/hashemi)\
**Post date:** [January 26, 2018, 1:56pm UTC](https://forums.swift.org/t/constrain-protocol-usage-outside-the-module/8832/13 "2018-01-26T13:56:52Z")

</div>

The part I’m most interested in is that `@closed` disallows consumers of the module from conforming their own types to a protocol. This, in turn, means that we can generate an exhaustive list of all types that conform to a certain protocol since they’re all within the module. Therefore, we can perform an exhaustive switch over those types.

```swift
switch intOrString {
  case let int as Int: print(int*int)
  case let str as String: print(“\(str) squared”)
  // no default necessary & will get a non-exhaustive error if we conform another type to IntOrString in the future
}

```

EDIT: of course this exhaustive switching will only work within the module, clients still need to be resilient to potential future changes in the module they’re consuming

---

_[View the full topic](https://forums.swift.org/t/constrain-protocol-usage-outside-the-module/8832)._
