Skip to content

Commit dfbadaf

Browse files
n3vu0rmbrubeck
authored andcommitted
Support safe rkyv API.
1 parent 0523158 commit dfbadaf

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

.github/workflows/tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,4 @@ jobs:
7878
args: --features ${{ env.all_features }}
7979

8080
env:
81-
all_features: "bytemuck,rand,randtest,serde,schemars,proptest,rkyv,speedy"
81+
all_features: "bytemuck,rand,randtest,serde,schemars,proptest,rkyv,rkyv_ck,speedy"

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ edition = "2021"
1616
[dependencies]
1717
num-traits = { version = "0.2.1", default-features = false }
1818
serde = { version = "1.0", optional = true, default-features = false }
19-
rkyv = { version = "0.7", optional = true, default-features = false }
19+
rkyv = { version = "0.7.41", optional = true, default-features = false }
2020
schemars = { version = "0.8.8", optional = true }
2121
rand = { version = "0.8.3", optional = true, default-features = false }
2222
arbitrary = { version = "1.0.0", optional = true }
@@ -36,3 +36,4 @@ rkyv = ["rkyv_32"]
3636
rkyv_16 = ["dep:rkyv", "rkyv?/size_16"]
3737
rkyv_32 = ["dep:rkyv", "rkyv?/size_32"]
3838
rkyv_64 = ["dep:rkyv", "rkyv?/size_64"]
39+
rkyv_ck = ["rkyv?/validation"]

src/lib.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,6 +1740,29 @@ mod impl_rkyv {
17401740
}
17411741
}
17421742

1743+
#[cfg(feature = "rkyv_ck")]
1744+
use rkyv::bytecheck::CheckBytes;
1745+
1746+
#[cfg(feature = "rkyv_ck")]
1747+
impl<C: ?Sized, T: CheckBytes<C>> CheckBytes<C> for OrderedFloat<T> {
1748+
type Error = T::Error;
1749+
1750+
#[inline]
1751+
unsafe fn check_bytes<'a>(value: *const Self, c: &mut C) -> Result<&'a Self, Self::Error> {
1752+
T::check_bytes(value as *const T, c).map(|_| &*value)
1753+
}
1754+
}
1755+
1756+
#[cfg(feature = "rkyv_ck")]
1757+
impl<C: ?Sized, T: CheckBytes<C>> CheckBytes<C> for NotNan<T> {
1758+
type Error = T::Error;
1759+
1760+
#[inline]
1761+
unsafe fn check_bytes<'a>(value: *const Self, c: &mut C) -> Result<&'a Self, Self::Error> {
1762+
T::check_bytes(value as *const T, c).map(|_| &*value)
1763+
}
1764+
}
1765+
17431766
#[test]
17441767
fn test_ordered_float() {
17451768
let float = OrderedFloat(1.0f64);

0 commit comments

Comments
 (0)