title: Returning a generic type through an associated type
body: <p>I try to get something more generic done but am failing on trying it with associated types. Given is a <code>Shape</code> trait and a <code>Renderer</code> type which tries to return a <code>Builder</code> for a specific kind of shape.</p>
  
  <p><strong>shape</strong></p>
  
  <pre><code>#[derive(Clone, Copy)]
  pub struct Rectangle{
      pub origin: Point,
      pub height: usize,
      pub width: usize,
  }
  
  pub trait Shape{
      type Builder : ShapeBuilder;
  }
  
  impl Shape for Rectangle{
      type Builder = RectangleBuilder;
  }
  </code></pre>
  
  <p><strong>builder</strong></p>
  
  <pre><code>pub trait ShapeBuilder{
      type Renderer: ShapeRenderer;
      fn set_origin() -&gt; Self::Renderer;
  }
  
  pub struct RectangleBuilder;
  
  impl ShapeBuilder for RectangleBuilder{
      type Renderer = RectangleRenderer;
      fn set_origin() -&gt; Self::Renderer{
          RectangleRenderer
      }
  }
  </code></pre>
  
  <p><strong>renderer</strong></p>
  
  <pre><code>pub struct Renderer&lt;'a&gt;{
      canvas:&amp;'a mut Canvas
  }
  
  impl &lt;'a&gt;Renderer&lt;'a&gt;{
      pub fn new(canvas:&amp;'a mut Canvas) -&gt; Renderer {
          Renderer{
              canvas: canvas
          }
      }
      pub fn set_shape&lt;T: Shape&gt;(&amp;self, shape: T) -&gt; T::Builder{
          // trying to return the specific builder through shape::Builder
          // or something like that
      }
  }
  </code></pre>
  
  <p>What I want to achieve is that the <code>set_shape</code> method will return the <code>RectangleBuilder</code> <strong>if</strong> the given <code>shape</code> is of type <code>Rectangle</code></p>