describe custom de/ser-ializer

This commit is contained in:
Marc-Antoine Arnaud 2018-05-13 10:12:01 +02:00
parent 9c274da9be
commit d6e7a07cc2

View File

@ -19,3 +19,25 @@ This library will support XML de/ser-ializing with all specific features.
- [x] **attribute**: this field is defined as an attribute
- [x] **text**: this field match to the text content
- [ ] **namespace**: defines the namespace of the field
## Custom De/Ser-rializer
Any type can define a custom deserializer and/or serializer.
To implement it, define the implementation of YaDeserialize/YaSerialize
```rust
impl YaDeserialize for MyType {
fn deserialize<R: Read>(reader: &mut yaserde::de::Deserializer<R>) -> Result<Self, String> {
// deserializer code
}
}
```
```rust
impl YaSerialize for MyType {
fn serialize<W: Write>(&self, writer: &mut yaserde::ser::Serializer<W>) -> Result<(), String> {
// serializer code
}
}
```