title: Generics and Constraints (`Instance method '...' requires that 'T' conform to 'Decodable'`)
body: <p>I have a generic struct allowing different types to be used. I do not want to constrain the whole struct to only Decodable items.</p>
  <p>What is the best way to fix the following error, where I try to only execute some code if T conforms to Decodable:
  <code>Instance method '...' requires that 'T' conform to 'Decodable'</code></p>
  <pre><code>struct Something&lt;T&gt; {
      ...
  
      func item&lt;T&gt;(from data: Data) -&gt; T? where T: Decodable {
          try? JSONDecoder().decode(T.self, from: data)
      }
      
      func getter() -&gt; T {
          let value = ...
          
          if let value = value as? T { return value } // something simple like string
          if let data = value as? Data, T.self is Decodable { // something complex
              return item(from: data) ?? defaultValue // error is thrown here
          }
          
          return defaultValue
      }
  }
  </code></pre>
  <p>As you can see I'm checking the conformance with the if-clause, but that isn't enough to access the constrained method? :/</p>