Skip to content

Commit

Permalink
Allow deserializing from newtype structs too (#672)
Browse files Browse the repository at this point in the history
* Allow deserializing from newtype structs too

* update changelog

* cargo fmt

* Update changelog date

Co-authored-by: Andronik <write@reusable.software>

Co-authored-by: Andronik <write@reusable.software>
  • Loading branch information
jsdw and ordian committed Sep 2, 2022
1 parent 706c989 commit aeca7d6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion primitive-types/impls/serde/CHANGELOG.md
Expand Up @@ -4,8 +4,9 @@ The format is based on [Keep a Changelog].

[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/

## [0.4.0] - 2022-08-31
## [0.4.0] - 2022-09-02
- Support deserializing H256 et al from bytes or sequences of bytes, too. [#668](https://github.com/paritytech/parity-common/pull/668)
- Support deserializing H256 et al from newtype structs containing anything compatible, too. [#672](https://github.com/paritytech/parity-common/pull/672)
- Migrated to 2021 edition, enforcing MSRV of `1.56.1`. [#601](https://github.com/paritytech/parity-common/pull/601)

## [0.3.2] - 2021-11-10
Expand Down
8 changes: 8 additions & 0 deletions primitive-types/impls/serde/src/serialize.rs
Expand Up @@ -231,6 +231,10 @@ where
}
Ok(bytes)
}

fn visit_newtype_struct<D: Deserializer<'b>>(self, deserializer: D) -> Result<Self::Value, D::Error> {
deserializer.deserialize_bytes(self)
}
}

deserializer.deserialize_str(Visitor)
Expand Down Expand Up @@ -309,6 +313,10 @@ where
}
self.visit_byte_buf(v)
}

fn visit_newtype_struct<D: Deserializer<'b>>(self, deserializer: D) -> Result<Self::Value, D::Error> {
deserializer.deserialize_bytes(self)
}
}

deserializer.deserialize_str(Visitor { len })
Expand Down

0 comments on commit aeca7d6

Please sign in to comment.