@@ -1917,59 +1917,101 @@ mod impl_rkyv {
19171917 use num_traits:: Float ;
19181918 #[ cfg( test) ]
19191919 use rkyv:: { archived_root, ser:: Serializer } ;
1920- use rkyv:: { from_archived , Archive , Deserialize , Fallible , Serialize } ;
1920+ use rkyv:: { Archive , Deserialize , Fallible , Serialize } ;
19211921
19221922 #[ cfg( test) ]
19231923 type DefaultSerializer = rkyv:: ser:: serializers:: CoreSerializer < 16 , 16 > ;
19241924 #[ cfg( test) ]
19251925 type DefaultDeserializer = rkyv:: Infallible ;
19261926
19271927 impl < T : Float + Archive > Archive for OrderedFloat < T > {
1928- type Archived = OrderedFloat < T > ;
1928+ type Archived = OrderedFloat < T :: Archived > ;
19291929
1930- type Resolver = ( ) ;
1930+ type Resolver = T :: Resolver ;
19311931
1932- unsafe fn resolve ( & self , _ : usize , _ : Self :: Resolver , out : * mut Self :: Archived ) {
1933- out. write ( * self ) ;
1932+ unsafe fn resolve ( & self , pos : usize , resolver : Self :: Resolver , out : * mut Self :: Archived ) {
1933+ self . 0 . resolve ( pos , resolver , out. cast ( ) )
19341934 }
19351935 }
19361936
19371937 impl < T : Float + Serialize < S > , S : Fallible + ?Sized > Serialize < S > for OrderedFloat < T > {
1938- fn serialize ( & self , _ : & mut S ) -> Result < Self :: Resolver , S :: Error > {
1939- Ok ( ( ) )
1938+ fn serialize ( & self , s : & mut S ) -> Result < Self :: Resolver , S :: Error > {
1939+ self . 0 . serialize ( s )
19401940 }
19411941 }
19421942
1943- impl < T : Float + Deserialize < T , D > , D : Fallible + ?Sized > Deserialize < OrderedFloat < T > , D >
1944- for OrderedFloat < T >
1943+ impl < T : Float , AT : Deserialize < T , D > , D : Fallible + ?Sized > Deserialize < OrderedFloat < T > , D >
1944+ for OrderedFloat < AT >
19451945 {
1946- fn deserialize ( & self , _ : & mut D ) -> Result < OrderedFloat < T > , D :: Error > {
1947- Ok ( from_archived ! ( * self ) )
1946+ fn deserialize ( & self , d : & mut D ) -> Result < OrderedFloat < T > , D :: Error > {
1947+ self . 0 . deserialize ( d ) . map ( OrderedFloat )
19481948 }
19491949 }
19501950
19511951 impl < T : Float + Archive > Archive for NotNan < T > {
1952- type Archived = NotNan < T > ;
1952+ type Archived = NotNan < T :: Archived > ;
19531953
1954- type Resolver = ( ) ;
1954+ type Resolver = T :: Resolver ;
19551955
1956- unsafe fn resolve ( & self , _ : usize , _ : Self :: Resolver , out : * mut Self :: Archived ) {
1957- out. write ( * self ) ;
1956+ unsafe fn resolve ( & self , pos : usize , resolver : Self :: Resolver , out : * mut Self :: Archived ) {
1957+ self . 0 . resolve ( pos , resolver , out. cast ( ) )
19581958 }
19591959 }
19601960
19611961 impl < T : Float + Serialize < S > , S : Fallible + ?Sized > Serialize < S > for NotNan < T > {
1962- fn serialize ( & self , _ : & mut S ) -> Result < Self :: Resolver , S :: Error > {
1963- Ok ( ( ) )
1962+ fn serialize ( & self , s : & mut S ) -> Result < Self :: Resolver , S :: Error > {
1963+ self . 0 . serialize ( s )
19641964 }
19651965 }
19661966
1967- impl < T : Float + Deserialize < T , D > , D : Fallible + ?Sized > Deserialize < NotNan < T > , D > for NotNan < T > {
1968- fn deserialize ( & self , _: & mut D ) -> Result < NotNan < T > , D :: Error > {
1969- Ok ( from_archived ! ( * self ) )
1967+ impl < T : Float , AT : Deserialize < T , D > , D : Fallible + ?Sized > Deserialize < NotNan < T > , D >
1968+ for NotNan < AT >
1969+ {
1970+ fn deserialize ( & self , d : & mut D ) -> Result < NotNan < T > , D :: Error > {
1971+ self . 0 . deserialize ( d) . map ( NotNan )
19701972 }
19711973 }
19721974
1975+ macro_rules! rkyv_eq_ord {
1976+ ( $main: ident, $float: ty, $rend: ty) => {
1977+ impl PartialEq <$main<$float>> for $main<$rend> {
1978+ fn eq( & self , other: & $main<$float>) -> bool {
1979+ other. eq( & self . 0 . value( ) )
1980+ }
1981+ }
1982+ impl PartialEq <$main<$rend>> for $main<$float> {
1983+ fn eq( & self , other: & $main<$rend>) -> bool {
1984+ self . eq( & other. 0 . value( ) )
1985+ }
1986+ }
1987+
1988+ impl PartialOrd <$main<$float>> for $main<$rend> {
1989+ fn partial_cmp( & self , other: & $main<$float>) -> Option <core:: cmp:: Ordering > {
1990+ self . 0 . value( ) . partial_cmp( other)
1991+ }
1992+ }
1993+
1994+ impl PartialOrd <$main<$rend>> for $main<$float> {
1995+ fn partial_cmp( & self , other: & $main<$rend>) -> Option <core:: cmp:: Ordering > {
1996+ other
1997+ . 0
1998+ . value( )
1999+ . partial_cmp( self )
2000+ . map( core:: cmp:: Ordering :: reverse)
2001+ }
2002+ }
2003+ } ;
2004+ }
2005+
2006+ rkyv_eq_ord ! { OrderedFloat , f32 , rkyv:: rend:: f32_le }
2007+ rkyv_eq_ord ! { OrderedFloat , f32 , rkyv:: rend:: f32_be }
2008+ rkyv_eq_ord ! { OrderedFloat , f64 , rkyv:: rend:: f64_le }
2009+ rkyv_eq_ord ! { OrderedFloat , f64 , rkyv:: rend:: f64_be }
2010+ rkyv_eq_ord ! { NotNan , f32 , rkyv:: rend:: f32_le }
2011+ rkyv_eq_ord ! { NotNan , f32 , rkyv:: rend:: f32_be }
2012+ rkyv_eq_ord ! { NotNan , f64 , rkyv:: rend:: f64_le }
2013+ rkyv_eq_ord ! { NotNan , f64 , rkyv:: rend:: f64_be }
2014+
19732015 #[ cfg( feature = "rkyv_ck" ) ]
19742016 use super :: FloatIsNan ;
19752017 #[ cfg( feature = "rkyv_ck" ) ]
0 commit comments