mozilla/rust — pull request #3520 by erickt (2012-09-18 05:45:51+00:00)
Title: trait-based serialization and auto-serialization

This adds trait-based serialization and auto-serialization. It's parallel with the old serialization library to help with the migration. This has the same approach as the old function-based one, just with traits. Because of this, we can simplify down auto-serialization to handling just records, structs, and enums. Everything else can be implemented in the library.

There are some downsides to the trait-based approach though:

* We lose support for auto-serializing arbitrary-sized tuples. Instead we must extend `serialization2.rs` if we want to automatically support more than 5 argument tuples.
* Pretty much every use of `#[auto_serialize]` requires this preamble at the top of the file, which would be nice to auto-generate.

```
extern mod std;
use std::serialization2::{Serializable, deserializer}
```

* I have no idea how to support mutable fields. I have a cut down version of my problem [here](https://gist.github.com/3740847). I can't throw `pure` everywhere, because serializers might not be pure. I could change the `serialize` signature to `fn serialize(&mut self) { ... }` but then everything that will be serialized must be stored in a `let mut ...` slot. Oddly enough the old function-based approach does not have this problem.