title: Handling return of enum with generic and non generic type in rust
body: <p>I am trying to create striped down redis clone in Rust. I got stuck trying to implement redis protocol.
  I want to have a struct that would encapsulate incoming packet and parse it appropriately to its data type and command.</p>
  <p>My data types are simple Strings or Ints, but one thing is kinda different for Array data type i would like to use <code>Vec&lt;T&gt;</code>  and this is where my problems begin.</p>
  <p>So i created struct that represents my incoming packet.
  What to want to archive with this struct to be able to just do:
  <code>let parsed_value = ProtocolPacket::new(data: &amp;[u8])</code></p>
  <pre><code>struct ProtocolPacket &lt;T&gt; {  //  &lt;-- this &lt;T&gt; is only because of ProtocolPacketData&lt;T&gt;
      command: ProtocolPacketCommand,
      data: ProtocolPacketData&lt;T&gt;,
  }
  impl &lt;T&gt;ProtocolPacket &lt;T&gt; {
      fn new(packet: &amp;[u8]) -&gt; ProtocolPacket&lt;T&gt; {
          let packet = packet.into_iter();
          let command = ProtocolPacketCommand::new(packet.next().unwrap()); // &lt;-- This is working
      // Delete \r \n
      packet.next_back().unwrap();
      packet.next_back().unwrap();
  
      let data = packet.as_slice();
      let data = ProtocolPacketData::new(data);
  
  
      ProtocolPacket{
          command: command,
          data: data,
      }
  }
  enum ProtocolPacketData &lt;T&gt; {
      SimpleString(String), 
      Error(String),
      Integer(i64), 
      String(String), 
      Array(Vec&lt;T&gt;),
  }
  
  impl &lt;T&gt; ProtocolPacketData &lt;T&gt; {
      pub fn new(rest: &amp;[u8]) -&gt; ProtocolPacketData&lt;T&gt; {
          let rest = rest.into_iter();
          let data_type  = rest.next().unwrap();
  
          // Strip last 2 bytes -&gt; \r\n
          rest.next_back().unwrap();
          rest.next_back().unwrap();
  
          match data_type.to_string().chars().next().unwrap() {
              '+' =&gt; handle_packet_simplestring(rest.as_slice()), &lt;-- Function call that returns ProtocolPacketData&lt;String&gt;
              '-' =&gt;   unimplemented!()
              ':' =&gt;   unimplemented!()
              '$' =&gt;   unimplemented!()
              '*' =&gt;   unimplemented!()
              '%' =&gt;   unimplemented!()
              _ =&gt;    unimplemented!()
          }
      }
  }
  
  
  fn handle_packet_simplestring&lt;T&gt;(packet_value: &amp;[u8]) -&gt; ProtocolPacketData&lt;String&gt;{
      let data = String::from_utf8_lossy(packet_value);
      ProtocolPacketData::SimpleString(data.to_string())
  }
  </code></pre>
  <p>This is where my error occours</p>
  <pre><code>    match data_type.to_string().chars().next().unwrap() {
          '+' =&gt; handle_packet_simplestring(rest.as_slice()), &lt;-- Function call that returns ProtocolPacketData&lt;String&gt;
          '-' =&gt;   unimplemented!()
          ':' =&gt;   unimplemented!()
          '$' =&gt;   unimplemented!()
          '*' =&gt;   unimplemented!()
          '%' =&gt;   unimplemented!()
          _ =&gt;    unimplemented!()
      }
  </code></pre>
  <p>I get an error</p>
  <pre><code>mismatched types
  expected enum ProtocolPacketData&lt;T&gt;
     found enum ProtocolPacketData&lt;std::string::String&gt;
  </code></pre>
  <p>How can i make this work and is this even viable way to do this?
  Thanks, Sam</p>