Factor attr parsing into serde_item crate
Fixes#396. @KodrAus [let me know whether this fits the bill.](5c6a0e12e9/serde_item/src)
a few other changes to make the API a little more presentable:
- Rename attr::{ContainerAttrs,VariantAttrs,FieldAttrs} to remove the "Attrs" (I see you worked on the corresponding [clippy lint](https://github.com/Manishearth/rust-clippy/issues/904)).
- Rename attr::Container* to attr::Item to correspond with item::Item and ast::Item. The others already had a correspondence (attr::Variant/item::Variant/ast::Variant, attr::Field/item::Field/ast::Field). Also a unit struct isn't much of a "container."
- Change item::Item::from_ast to return a meaningful error enum instead of printing a message that was hard to generalize to other uses.
- Add item::Variant.span for consistency because Item and Field already had span.
- Remove the "ident" field from attr::Name because we can just fold it into the other two fields.
- Remove attr::Name::(de)serialize_name_expr because it wasn't using the right AstBuilder in the first place.
- Rename the attr:: constructors from_item/from_variant/from_field to from_ast to line up with the item:: constructors; the signatures match.
- Remove attr's dependency on aster because we were only using it for two very simple things.
Better error when deriving Deserialize for struct containing &str
Fixes#360. The error looks like this:
```rust
#[derive(Serialize, Deserialize)]
struct Test<'a> {
s: &'a str,
}
```
```
src/main.rs:6:5: 6:15 error: Serde does not support deserializing fields of type &str; consider using String instead
src/main.rs:6 s: &'a str,
^~~~~~~~~~
```
Add serde_codegen::expand to avoid public Syntex dependency
Required for #358. We can remove `serde_codegen::register` in the next breaking release.
This allows Syntex users to avoid being broken by Serde bumping its Syntex dependency.
Attribute for handwritten where clauses
Addresses (2) and (3) in https://github.com/serde-rs/serde/issues/336#issuecomment-220378916.
- If there is a `#[serde(bound="...")]` attribute on the type, use the union of that and the actual type's `where` clause as the `where` clause for the impl and do not attempt to generate any additional `where` clauses whatsoever.
- If there is a `#[serde(bound="...")]` attribute on a field, use that and do not attempt to generate any additional `where` clauses for the field.
The `bound` attribute behaves similar to `rename` in that you can specify a single attribute that applies to both ser and de, or individual ones.
```
#[serde(bound="D: Serialize + Deserialize")]
#[serde(bound(serialize="D: Serialize", deserialize="D: Deserialize"))]
```
EDIT: now addresses (4) from https://github.com/serde-rs/serde/issues/336#issuecomment-220378916 as well.
- If a field contains direct recursion, do not generate any bounds based on that field except from `bound` attributes.