Skip to content

Commit

Permalink
Merge pull request #1072 from LinearZoetrope/wrapping
Browse files Browse the repository at this point in the history
Add std::num::Wrapping impl
  • Loading branch information
dtolnay authored Oct 31, 2017
2 parents aa03fd5 + a7e4911 commit eebf0f8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
17 changes: 17 additions & 0 deletions serde/src/de/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
16 changes: 16 additions & 0 deletions serde/src/ser/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit eebf0f8

Please sign in to comment.