diff --git a/src/de/impls.rs b/src/de/impls.rs index fd4f42e4..3bb46c2b 100644 --- a/src/de/impls.rs +++ b/src/de/impls.rs @@ -11,11 +11,12 @@ use core::{ cell::{Cell, RefCell}, num::{ NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize, NonZeroU128, - NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize, + NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize, Wrapping, }, ops::{Bound, Range, RangeInclusive}, time::Duration, }; +use std::cmp::Reverse; impl Decode for bool { fn decode(decoder: &mut D) -> Result { @@ -394,6 +395,29 @@ impl Decode for f64 { } impl_borrow_decode!(f64); +impl Decode for Wrapping { + fn decode(decoder: &mut D) -> Result { + Ok(Wrapping(T::decode(decoder)?)) + } +} +impl<'de, T: BorrowDecode<'de>> BorrowDecode<'de> for Wrapping { + fn borrow_decode>(decoder: &mut D) -> Result { + Ok(Wrapping(T::borrow_decode(decoder)?)) + } +} + +impl Decode for Reverse { + fn decode(decoder: &mut D) -> Result { + Ok(Reverse(T::decode(decoder)?)) + } +} + +impl<'de, T: BorrowDecode<'de>> BorrowDecode<'de> for Reverse { + fn borrow_decode>(decoder: &mut D) -> Result { + Ok(Reverse(T::borrow_decode(decoder)?)) + } +} + impl Decode for char { fn decode(decoder: &mut D) -> Result { let mut array = [0u8; 4]; diff --git a/src/enc/impls.rs b/src/enc/impls.rs index efaadac3..a62e7bfc 100644 --- a/src/enc/impls.rs +++ b/src/enc/impls.rs @@ -8,11 +8,12 @@ use core::{ marker::PhantomData, num::{ NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize, NonZeroU128, - NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize, + NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize, Wrapping, }, ops::{Bound, Range, RangeInclusive}, time::Duration, }; +use std::cmp::Reverse; impl Encode for () { fn encode(&self, _: &mut E) -> Result<(), EncodeError> { @@ -274,6 +275,18 @@ impl Encode for f64 { } } +impl Encode for Wrapping { + fn encode(&self, encoder: &mut E) -> Result<(), EncodeError> { + self.0.encode(encoder) + } +} + +impl Encode for Reverse { + fn encode(&self, encoder: &mut E) -> Result<(), EncodeError> { + self.0.encode(encoder) + } +} + impl Encode for char { fn encode(&self, encoder: &mut E) -> Result<(), EncodeError> { encode_utf8(encoder.writer(), *self) diff --git a/tests/basic_types.rs b/tests/basic_types.rs index b6773683..af83cad8 100644 --- a/tests/basic_types.rs +++ b/tests/basic_types.rs @@ -4,6 +4,7 @@ use bincode::error::DecodeError; use core::cell::{Cell, RefCell}; use core::ops::Bound; use core::time::Duration; +use std::cmp::Reverse; use std::num::*; use utils::{the_same, the_same_with_comparer}; @@ -113,6 +114,36 @@ fn test_numbers() { the_same(NonZeroI128::new(12345)); the_same(NonZeroIsize::new(0)); the_same(NonZeroIsize::new(12345)); + + // Wrapping types + the_same(Wrapping(5u8)); + the_same(Wrapping(5u16)); + the_same(Wrapping(5u32)); + the_same(Wrapping(5u64)); + the_same(Wrapping(5u128)); + the_same(Wrapping(5usize)); + + the_same(Wrapping(5i8)); + the_same(Wrapping(5i16)); + the_same(Wrapping(5i32)); + the_same(Wrapping(5i64)); + the_same(Wrapping(5i128)); + the_same(Wrapping(5isize)); + + // Reverse types + the_same(Reverse(5u8)); + the_same(Reverse(5u16)); + the_same(Reverse(5u32)); + the_same(Reverse(5u64)); + the_same(Reverse(5u128)); + the_same(Reverse(5usize)); + + the_same(Reverse(5i8)); + the_same(Reverse(5i16)); + the_same(Reverse(5i32)); + the_same(Reverse(5i64)); + the_same(Reverse(5i128)); + the_same(Reverse(5isize)); } #[test]