Merge pull request #1072 from LinearZoetrope/wrapping

Add std::num::Wrapping impl
This commit is contained in:
David Tolnay 2017-10-31 09:26:17 -07:00 committed by GitHub
commit eebf0f8db8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 0 deletions

View File

@ -1825,3 +1825,20 @@ where
deserializer.deserialize_enum("Result", VARIANTS, ResultVisitor(PhantomData))
}
}
////////////////////////////////////////////////////////////////////////////////
#[cfg(feature = "std")]
use std::num::Wrapping;
#[cfg(feature = "std")]
impl<'de, T> Deserialize<'de> for Wrapping<T>
where
T: Deserialize<'de>
{
fn deserialize<D>(deserializer: D) -> Result<Wrapping<T>, D::Error>
where D: Deserializer<'de>
{
Deserialize::deserialize(deserializer).map(Wrapping)
}
}

View File

@ -664,3 +664,19 @@ impl Serialize for OsString {
self.as_os_str().serialize(serializer)
}
}
////////////////////////////////////////////////////////////////////////////////
#[cfg(feature = "std")]
use std::num::Wrapping;
#[cfg(feature = "std")]
impl<T: Serialize> Serialize for Wrapping<T> {
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
self.0.serialize(serializer)
}
}