add serde impls for Unwrapped types

This commit is contained in:
Trevor Spiteri 2020-10-02 14:16:52 +02:00
parent 3e1c1a642d
commit 75d8d2ef93
2 changed files with 18 additions and 1 deletions

View File

@ -208,7 +208,7 @@ x86_64-gnulinux-tarpaulin:
image: amd64/rust:1
variables:
TARGET: x86_64
REQ_COVERAGE: "79.7"
REQ_COVERAGE: "79.6"
cache:
key: $CI_JOB_NAME
paths:

View File

@ -13,6 +13,8 @@
// <https://www.apache.org/licenses/LICENSE-2.0> and
// <https://opensource.org/licenses/MIT>.
#[cfg(feature = "unwrapped")]
use crate::Unwrapped;
use crate::{
types::extra::{LeEqU128, LeEqU16, LeEqU32, LeEqU64, LeEqU8},
FixedI128, FixedI16, FixedI32, FixedI64, FixedI8, FixedU128, FixedU16, FixedU32, FixedU64,
@ -34,12 +36,20 @@ macro_rules! serde_fixed {
state.end()
}
}
impl<Frac: $LeEqU> Serialize for Wrapping<$Fixed<Frac>> {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
self.0.serialize(serializer)
}
}
#[cfg(feature = "unwrapped")]
impl<Frac: $LeEqU> Serialize for Unwrapped<$Fixed<Frac>> {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
self.0.serialize(serializer)
}
}
impl<'de, Frac: $LeEqU> Deserialize<'de> for $Fixed<Frac> {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
struct FixedVisitor;
@ -86,6 +96,13 @@ macro_rules! serde_fixed {
$Fixed::deserialize(deserializer).map(Wrapping)
}
}
#[cfg(feature = "unwrapped")]
impl<'de, Frac: $LeEqU> Deserialize<'de> for Unwrapped<$Fixed<Frac>> {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
$Fixed::deserialize(deserializer).map(Unwrapped)
}
}
};
}