title: sqlx: implementing Decode and Type<DB> for associated trait type
body: <p>I am trying to create a library which gets Values for multiple Tags from an SQL Database. Depending on the TagType which can be Analog or String - I need to return the matching value type. I tried to achieve this using a associated type named <code>ValueType</code> in the <code>Tag</code> trait</p>
  <p>This is what i have got until now:</p>
  <pre class="lang-rust prettyprint-override"><code>use sqlx::Row;
  
  pub trait Tag {
      type ValueType;
  
      fn name(&amp;self) -&gt; String;
      fn tagtype(&amp;self) -&gt; TagType;
  }
  
  pub enum TagType {
      Analog = 1,
      String = 3,
  }
  
  pub struct AnalogTag(String);
  pub struct StringTag(String);
  
  impl Tag for AnalogTag {
      type ValueType = f64;
  
      fn name(&amp;self) -&gt; String {
          self.0.to_string()
      }
  
      fn tagtype(&amp;self) -&gt; TagType {
          TagType::Analog
      }
  }
  
  impl Tag for StringTag {
      type ValueType = String;
  
      fn name(&amp;self) -&gt; String {
          self.0.to_string()
      }
  
      fn tagtype(&amp;self) -&gt; TagType {
          TagType::String
      }
  }
  
  pub struct Value&lt;T&gt; {
      pub val: T,
      pub quality: i8,
  }
  
  impl&lt;T&gt; Value&lt;T&gt; {
      fn new(val: T, quality: i8) -&gt; Self {
          Self { val, quality }
      }
  }
  
  pub async fn get_actual_value&lt;T: Tag&gt;(
      db_pool: sqlx::MssqlPool,
      tag: T,
  ) -&gt; Result&lt;Value&lt;T::ValueType&gt;, sqlx::Error&gt; {
      let table = match tag.tagtype() {
          TagType::Analog =&gt; &quot;AnalogLive&quot;,
          TagType::String =&gt; &quot;StringLive&quot;,
      };
      let result = sqlx::query(&quot;SELECT Value, Quality FROM @P1 WHERE Tagname = @P2&quot;)
          .bind(table)
          .bind(tag.name())
          .fetch_one(&amp;db_pool)
          .await?;
      let val = result.get(&quot;Value&quot;);
      let quality: i8 = result.get(&quot;Quality&quot;);
      Ok(Value::new(val, quality))
  }
  </code></pre>
  <p>Anyhow, this will not work.
  I need to implement <code>sqlx::Decode</code> and <code>Type&lt;Mssql&gt;</code> traits but don't know how this can be done for <code>ValueType</code> that is an associated type of the trait <code>Tag</code></p>
  <blockquote>
  <p>the trait <code>sqlx::Decode&lt;'_, Mssql&gt;</code> is not implemented for <code>&lt;T as Tag&gt;::ValueType</code>
  the trait <code>Type&lt;Mssql&gt;</code> is not implemented for <code>&lt;T as Tag&gt;::ValueType</code></p>
  </blockquote>
  <p>Any help would be appreciated!</p>
  <p><strong>EDIT</strong>
  Updated the code-example to a minimal reproducible example</p>