title: Custom diesel type
body: <p>I'm trying to implement a custom Diesel type using ToSql/FromSql traits.</p>
  <p><strong>My code now looks like this:</strong></p>
  <pre class="lang-rust prettyprint-override"><code>use diesel::{
      backend::Backend,
      deserialize,
      serialize,
      sql_types::VarChar,
  };
  
  #[derive(AsExpression, FromSqlRow, Debug)]
  #[sql_type = &quot;VarChar&quot;]
  pub struct File {
      id: String,
  }
  
  impl File {
      pub fn new(id: String) -&gt; Self {
          Self { id }
      }
  }
  
  
  impl&lt;B: Backend&gt; serialize::ToSql&lt;VarChar, B&gt; for File {
      fn to_sql(&amp;self, out: &amp;mut serialize::Output&lt;B&gt;) -&gt; serialize::Result {
          &lt;String as serialize::ToSql&lt;VarChar, B&gt;&gt;::to_sql(&amp;self.id, out)
      }
  }
  
  impl&lt;B: Backend&lt;RawValue=[u8]&gt;&gt; deserialize::FromSql&lt;VarChar, B&gt; for File {
      fn from_sql(bytes: Option&lt;&amp;B::RawValue&gt;) -&gt; deserialize::Result&lt;Self&gt; {
          &lt;String as deserialize::FromSql&lt;VarChar, B&gt;&gt;::from_sql(bytes).map(|id| File::new(id))
      }
  }
  </code></pre>
  <p>When I try to compile it, I receive a bunch of errors.
  A couple of them are related to inability to detect names.</p>
  <pre class="lang-rust prettyprint-override"><code>error: cannot find derive macro `AsExpression` in this scope
   --&gt; src\file.rs:8:10                                       
    |                                                         
  8 | #[derive(AsExpression, FromSqlRow, Debug)]              
    |          ^^^^^^^^^^^^                                   
    |                                                         
    = note: consider importing this derive macro:             
            diesel::AsExpression                              
                                                              
  error: cannot find derive macro `FromSqlRow` in this scope  
   --&gt; src\file.rs:8:24                                       
    |                                                         
  8 | #[derive(AsExpression, FromSqlRow, Debug)]              
    |                        ^^^^^^^^^^                       
    |                                                         
    = note: consider importing one of these items:            
            crate::file::deserialize::FromSqlRow              
            diesel::FromSqlRow                                
  
  error: cannot find attribute `sql_type` in this scope
   --&gt; src\file.rs:9:3
    |
  9 | #[sql_type = &quot;VarChar&quot;]
    |   ^^^^^^^^
  </code></pre>
  <p>I thought the problem was because I hadn't added Diesel's prelude to my scope. But, unfortunately, when I do this, I encounter the same problem.</p>
  <p>The second problem looks like this:</p>
  <pre class="lang-rust prettyprint-override"><code>error[E0212]: cannot use the associated type of a trait with uninferred generic 
  parameters
    --&gt; src\file.rs:30:32
     |
  30 |     fn from_sql(bytes: Option&lt;&amp;B::RawValue&gt;) -&gt; deserialize::Result&lt;Self&gt; {
     |                                ^^^^^^^^^^^
     |
  help: use a fully qualified path with inferred lifetimes
     |
  30 |     fn from_sql(bytes: Option&lt;&amp;&lt;B as backend::private::HasRawValue&lt;'_&gt;&gt;::Ra
  wValue&gt;) -&gt; deserialize::Result&lt;Self&gt; {
     |                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
  </code></pre>
  <p>The compiler requires a fully qualified syntax although each example of custom types shows almost the same code.</p>