title: Constrain generic type by swift enum
body: <p>I would like to constrain a generic type in Swift by the choice of different enum cases.</p>
  <p>Below, a code example:</p>
  <pre><code>enum Test {
    case T1
    case T2
  }
  
  enum T1 {
    case one
    case two
  }
  
  enum T2 {
    case three
    case four
  }
  
  
  indirect enum Foo&lt;T&gt; {
    case empty
    case cons(T, Foo&lt;T&gt;)
  }
  
  let x: Foo&lt;T1&gt; = .cons(.one, .empty)
  </code></pre>
  <p>I have a first Enum which contains two cases with T1 and T2.
  I'm trying to constrain the type T in Foo Enum to have a collection of types available, which are T1 and T2 in my example.
  When I declare <code>x</code>, the allowed types are <code>T1</code>or <code>T2</code> contain in Test, not another type.
  Hence, only types in Enum <code>Test</code> must be allowed.</p>
  <p>My question: Is it possible to use my Enum to constrain the generic type ? If yes, how ?
  Otherwise, how can I do ?</p>