Skip to content

Commit

Permalink
Assume POD and re-check NotNan.
Browse files Browse the repository at this point in the history
  • Loading branch information
n3vu0r authored and mbrubeck committed Apr 3, 2023
1 parent dfbadaf commit d513f95
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1740,26 +1740,30 @@ mod impl_rkyv {
}
}

#[cfg(feature = "rkyv_ck")]
use super::FloatIsNan;
#[cfg(feature = "rkyv_ck")]
use core::convert::Infallible;
#[cfg(feature = "rkyv_ck")]
use rkyv::bytecheck::CheckBytes;

#[cfg(feature = "rkyv_ck")]
impl<C: ?Sized, T: CheckBytes<C>> CheckBytes<C> for OrderedFloat<T> {
type Error = T::Error;
impl<C: ?Sized, T: Float + CheckBytes<C>> CheckBytes<C> for OrderedFloat<T> {
type Error = Infallible;

#[inline]
unsafe fn check_bytes<'a>(value: *const Self, c: &mut C) -> Result<&'a Self, Self::Error> {
T::check_bytes(value as *const T, c).map(|_| &*value)
unsafe fn check_bytes<'a>(value: *const Self, _: &mut C) -> Result<&'a Self, Self::Error> {
Ok(&*value)
}
}

#[cfg(feature = "rkyv_ck")]
impl<C: ?Sized, T: CheckBytes<C>> CheckBytes<C> for NotNan<T> {
type Error = T::Error;
impl<C: ?Sized, T: Float + CheckBytes<C>> CheckBytes<C> for NotNan<T> {
type Error = FloatIsNan;

#[inline]
unsafe fn check_bytes<'a>(value: *const Self, c: &mut C) -> Result<&'a Self, Self::Error> {
T::check_bytes(value as *const T, c).map(|_| &*value)
unsafe fn check_bytes<'a>(value: *const Self, _: &mut C) -> Result<&'a Self, Self::Error> {
Self::new(*(value as *const T)).map(|_| &*value)
}
}

Expand Down

0 comments on commit d513f95

Please sign in to comment.