describe custom de/ser-ializer
This commit is contained in:
parent
9c274da9be
commit
d6e7a07cc2
22
README.md
22
README.md
@ -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
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Loading…
Reference in New Issue
Block a user