

Serialization in Rust - rnestler
http://rnestler.github.io/serialization-in-rust.html

======
dbrgn
The Encodable implementation can be simplified further in this case:

\- The match is not necessary for a single possible type. Simply use the "dot"
syntax. \- The return value of a closure can be derived automatically. `|enc|
-> _ {` can be simplified to `|enc| {`. \- An explicit return is not
necessary, simply leave an expression at the end of the scope. \- I'm not sure
why `p_url` was dereferenced, but `p_type` not. Apparently it's not necessary
at all. \- Some redundant braces can be removed.

Before:

    
    
      match *self {
          Feed { _type: ref p_type, url: ref p_url } =>
              encoder.emit_struct("Feed", 2usize, |enc| -> _ {
                  try!(enc.emit_struct_field( "type", 0usize, |enc| p_type.encode(enc)));
                  return enc.emit_struct_field("url", 1usize, |enc| -> _ { (*p_url).encode(enc) });
              }),
      }
    

After:

    
    
      encoder.emit_struct("Feed", 2usize, |enc| {
          try!(
              enc.emit_struct_field("type", 0usize, |enc| self._type.encode(enc))
          );
          enc.emit_struct_field("url", 1usize, |enc| self.url.encode(enc))
      })

