Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ jobs:
args: --features ${{ env.all_features }}

env:
all_features: "bytemuck,rand,randtest,serde,schemars,proptest,rkyv,speedy"
all_features: "bytemuck,rand,randtest,serde,schemars,proptest,rkyv,rkyv_ck,speedy"
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ edition = "2021"
[dependencies]
num-traits = { version = "0.2.1", default-features = false }
serde = { version = "1.0", optional = true, default-features = false }
rkyv = { version = "0.7", optional = true, default-features = false }
rkyv = { version = "0.7.41", optional = true, default-features = false }
schemars = { version = "0.8.8", optional = true }
rand = { version = "0.8.3", optional = true, default-features = false }
arbitrary = { version = "1.0.0", optional = true }
Expand All @@ -36,3 +36,4 @@ rkyv = ["rkyv_32"]
rkyv_16 = ["dep:rkyv", "rkyv?/size_16"]
rkyv_32 = ["dep:rkyv", "rkyv?/size_32"]
rkyv_64 = ["dep:rkyv", "rkyv?/size_64"]
rkyv_ck = ["rkyv?/validation"]
27 changes: 27 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1740,6 +1740,33 @@ 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: Float + CheckBytes<C>> CheckBytes<C> for OrderedFloat<T> {
type Error = Infallible;

#[inline]
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: Float + CheckBytes<C>> CheckBytes<C> for NotNan<T> {
type Error = FloatIsNan;

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

#[test]
fn test_ordered_float() {
let float = OrderedFloat(1.0f64);
Expand Down