Skip to content

Commit 557d556

Browse files
committed
wip migrating to rkyv 0.8 ; one compiling error type left
1 parent 0e8aed8 commit 557d556

File tree

16 files changed

+104
-128
lines changed

16 files changed

+104
-128
lines changed

Cargo.toml

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@ path = "src/lib.rs"
2323

2424
[features]
2525
default = ["std", "macros"]
26-
std = ["matrixmultiply", "num-traits/std", "num-complex/std", "num-rational/std", "approx/std", "simba/std"]
26+
std = [
27+
"matrixmultiply",
28+
"num-traits/std",
29+
"num-complex/std",
30+
"num-rational/std",
31+
"approx/std",
32+
"simba/std",
33+
]
2734
sparse = []
2835
debug = ["approx/num-complex", "rand"]
2936
alloc = []
@@ -59,20 +66,26 @@ convert-glam029 = ["glam029"]
5966
## `serde-serialize`.
6067
serde-serialize-no-std = ["serde", "num-complex/serde"]
6168
serde-serialize = ["serde-serialize-no-std", "serde/std"]
62-
rkyv-serialize-no-std = ["rkyv/size_32"]
63-
rkyv-serialize = ["rkyv-serialize-no-std", "rkyv/std", "rkyv/validation"]
69+
rkyv-serialize-no-std = ["rkyv/pointer_width_32"]
70+
rkyv-serialize = ["rkyv-serialize-no-std", "rkyv/std", "rkyv/bytecheck"]
6471

6572
# Randomness
6673
## To use rand in a #[no-std] environment, enable the
6774
## `rand-no-std` feature instead of `rand`.
6875
rand-no-std = ["rand-package"]
69-
rand = ["rand-no-std", "rand-package/std", "rand-package/std_rng", "rand-package/thread_rng", "rand_distr"]
76+
rand = [
77+
"rand-no-std",
78+
"rand-package/std",
79+
"rand-package/std_rng",
80+
"rand-package/thread_rng",
81+
"rand_distr",
82+
]
7083

7184
# Tests
7285
arbitrary = ["quickcheck"]
7386
proptest-support = ["proptest"]
7487
slow-tests = []
75-
rkyv-safe-deser = ["rkyv-serialize", "rkyv/validation"]
88+
rkyv-safe-deser = ["rkyv-serialize", "rkyv/bytecheck"]
7689

7790
[dependencies]
7891
nalgebra-macros = { version = "0.2.2", path = "nalgebra-macros", optional = true }
@@ -86,15 +99,19 @@ simba = { version = "0.9", default-features = false }
8699
alga = { version = "0.9", default-features = false, optional = true }
87100
rand_distr = { version = "0.5", default-features = false, optional = true }
88101
matrixmultiply = { version = "0.3", optional = true }
89-
serde = { version = "1.0", default-features = false, features = ["derive"], optional = true }
90-
rkyv = { version = "0.7.41", default-features = false, optional = true }
102+
serde = { version = "1.0", default-features = false, features = [
103+
"derive",
104+
], optional = true }
105+
rkyv = { version = "0.8", default-features = false, optional = true }
91106
mint = { version = "0.5", optional = true }
92107
quickcheck = { version = "1", optional = true }
93108
pest = { version = "2", optional = true }
94109
pest_derive = { version = "2", optional = true }
95110
bytemuck = { version = "1.5", optional = true }
96111
matrixcompare-core = { version = "0.1", optional = true }
97-
proptest = { version = "1", optional = true, default-features = false, features = ["std"] }
112+
proptest = { version = "1", optional = true, default-features = false, features = [
113+
"std",
114+
] }
98115
glam014 = { package = "glam", version = "0.14", optional = true }
99116
glam015 = { package = "glam", version = "0.15", optional = true }
100117
glam016 = { package = "glam", version = "0.16", optional = true }
@@ -129,7 +146,12 @@ trybuild = "1.0.90"
129146
cool_asserts = "2.0.3"
130147

131148
[workspace]
132-
members = ["nalgebra-lapack", "nalgebra-glm", "nalgebra-sparse", "nalgebra-macros"]
149+
members = [
150+
"nalgebra-lapack",
151+
"nalgebra-glm",
152+
"nalgebra-sparse",
153+
"nalgebra-macros",
154+
]
133155
resolver = "2"
134156

135157
[[example]]

src/base/array_storage.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
1111
#[cfg(feature = "serde-serialize-no-std")]
1212
use std::marker::PhantomData;
1313

14-
#[cfg(feature = "rkyv-serialize")]
15-
use rkyv::bytecheck;
16-
1714
use crate::base::allocator::Allocator;
1815
use crate::base::default_allocator::DefaultAllocator;
1916
use crate::base::dimension::{Const, ToTypenum};
@@ -33,15 +30,14 @@ use std::mem;
3330
#[cfg_attr(
3431
feature = "rkyv-serialize-no-std",
3532
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize),
36-
archive(
37-
as = "ArrayStorage<T::Archived, R, C>",
38-
bound(archive = "
39-
T: rkyv::Archive,
40-
[[T; R]; C]: rkyv::Archive<Archived = [[T::Archived; R]; C]>
41-
")
33+
rkyv(
34+
as = ArrayStorage<T::Archived, R, C>,
35+
archive_bounds(
36+
T: rkyv::Archive,
37+
[[T; R]; C]: rkyv::Archive<Archived = [[T::Archived; R]; C]>
38+
)
4239
)
4340
)]
44-
#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))]
4541
pub struct ArrayStorage<T, const R: usize, const C: usize>(pub [[T; R]; C]);
4642

4743
impl<T, const R: usize, const C: usize> ArrayStorage<T, R, C> {

src/base/dimension.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ use std::fmt::Debug;
88
use std::ops::{Add, Div, Mul, Sub};
99
use typenum::{self, Diff, Max, Maximum, Min, Minimum, Prod, Quot, Sum, Unsigned};
1010

11-
#[cfg(feature = "rkyv-serialize")]
12-
use rkyv::bytecheck;
1311
#[cfg(feature = "serde-serialize-no-std")]
1412
use serde::{Deserialize, Deserializer, Serialize, Serializer};
1513

@@ -19,10 +17,6 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
1917
feature = "rkyv-serialize-no-std",
2018
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
2119
)]
22-
#[cfg_attr(
23-
feature = "rkyv-serialize",
24-
archive_attr(derive(bytecheck::CheckBytes))
25-
)]
2620
pub struct Dyn(pub usize);
2721

2822
#[deprecated(note = "use Dyn instead.")]
@@ -216,9 +210,8 @@ dim_ops!(
216210
#[cfg_attr(
217211
feature = "rkyv-serialize-no-std",
218212
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize),
219-
archive(as = "Self")
213+
rkyv(derive(Debug), compare(PartialEq))
220214
)]
221-
#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))]
222215
pub struct Const<const R: usize>;
223216

224217
/// Trait implemented exclusively by type-level integers.

src/base/matrix.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
1313

1414
#[cfg(feature = "rkyv-serialize-no-std")]
1515
use super::rkyv_wrappers::CustomPhantom;
16-
#[cfg(feature = "rkyv-serialize")]
17-
use rkyv::bytecheck;
1816
#[cfg(feature = "rkyv-serialize-no-std")]
1917
use rkyv::{with::With, Archive, Archived};
2018

@@ -161,16 +159,14 @@ pub type MatrixCross<T, R1, C1, R2, C2> =
161159
#[cfg_attr(
162160
feature = "rkyv-serialize-no-std",
163161
derive(Archive, rkyv::Serialize, rkyv::Deserialize),
164-
archive(
165-
as = "Matrix<T::Archived, R, C, S::Archived>",
166-
bound(archive = "
167-
T: Archive,
168-
S: Archive,
169-
With<PhantomData<(T, R, C)>, CustomPhantom<(Archived<T>, R, C)>>: Archive<Archived = PhantomData<(Archived<T>, R, C)>>
170-
")
162+
rkyv(as = Matrix<T::Archived, R, C, S::Archived>,
163+
archive_bounds(
164+
T: Archive,
165+
S: Archive,
166+
With<PhantomData<(T, R, C)>, CustomPhantom<(Archived<T>, R, C)>>: Archive<Archived = PhantomData<(Archived<T>, R, C)>>
167+
)
171168
)
172169
)]
173-
#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))]
174170
pub struct Matrix<T, R, C, S> {
175171
/// The data storage that contains all the matrix components. Disappointed?
176172
///
@@ -207,7 +203,7 @@ pub struct Matrix<T, R, C, S> {
207203
// of the `RawStorage` trait. However, because we don't have
208204
// specialization, this is not possible because these `T, R, C`
209205
// allows us to desambiguate a lot of configurations.
210-
#[cfg_attr(feature = "rkyv-serialize-no-std", with(CustomPhantom<(T::Archived, R, C)>))]
206+
#[cfg_attr(feature = "rkyv-serialize-no-std", rkyv(with = CustomPhantom<(T::Archived, R, C)>))]
211207
_phantoms: PhantomData<(T, R, C)>,
212208
}
213209

src/base/rkyv_wrappers.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
//! Copied from <https://github.com/rkyv/rkyv_contrib> (MIT-Apache2 licences) which isn’t published yet.
44
55
use rkyv::{
6+
rancor::Fallible,
67
with::{ArchiveWith, DeserializeWith, SerializeWith},
7-
Fallible,
8+
Place,
89
};
910
use std::marker::PhantomData;
1011

@@ -18,13 +19,7 @@ impl<OT: ?Sized, NT: ?Sized> ArchiveWith<PhantomData<OT>> for CustomPhantom<NT>
1819
type Resolver = ();
1920

2021
#[inline]
21-
unsafe fn resolve_with(
22-
_: &PhantomData<OT>,
23-
_: usize,
24-
_: Self::Resolver,
25-
_: *mut Self::Archived,
26-
) {
27-
}
22+
fn resolve_with(_: &PhantomData<OT>, _: Self::Resolver, _: Place<Self::Archived>) {}
2823
}
2924

3025
impl<OT: ?Sized, NT: ?Sized, S: Fallible + ?Sized> SerializeWith<PhantomData<OT>, S>

src/base/unit.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ use crate::base::DefaultAllocator;
99
use crate::storage::RawStorage;
1010
use crate::{Dim, Matrix, OMatrix, RealField, Scalar, SimdComplexField, SimdRealField};
1111

12-
#[cfg(feature = "rkyv-serialize")]
13-
use rkyv::bytecheck;
14-
1512
/// A wrapper that ensures the underlying algebraic entity has a unit norm.
1613
///
1714
/// **It is likely that the only piece of documentation that you need in this page are:**
@@ -27,14 +24,12 @@ use rkyv::bytecheck;
2724
#[cfg_attr(
2825
feature = "rkyv-serialize-no-std",
2926
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize),
30-
archive(
31-
as = "Unit<T::Archived>",
32-
bound(archive = "
33-
T: rkyv::Archive,
34-
")
27+
rkyv(as = Unit<T::Archived>,
28+
archive_bounds(
29+
T: rkyv::Archive,
30+
)
3531
)
3632
)]
37-
#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))]
3833
pub struct Unit<T> {
3934
pub(crate) value: T,
4035
}

src/geometry/dual_quaternion.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,13 @@ use simba::scalar::{ClosedNeg, RealField};
4646
#[cfg_attr(
4747
feature = "rkyv-serialize-no-std",
4848
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize),
49-
archive(
50-
as = "DualQuaternion<T::Archived>",
51-
bound(archive = "
52-
T: rkyv::Archive,
53-
Quaternion<T>: rkyv::Archive<Archived = Quaternion<T::Archived>>
54-
")
49+
rkyv(as = DualQuaternion<T::Archived>,
50+
archive_bounds(
51+
T: rkyv::Archive,
52+
Quaternion<T>: rkyv::Archive<Archived = Quaternion<T::Archived>>
53+
)
5554
)
5655
)]
57-
#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))]
5856
pub struct DualQuaternion<T> {
5957
/// The real component of the quaternion
6058
pub real: Quaternion<T>,

src/geometry/isometry.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,15 @@ use rkyv::bytecheck;
7171
Owned<T, Const<D>>: Deserialize<'de>,
7272
T: Scalar"))
7373
)]
74-
#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))]
7574
#[cfg_attr(
7675
feature = "rkyv-serialize-no-std",
7776
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize),
78-
archive(
79-
as = "Isometry<T::Archived, R::Archived, D>",
80-
bound(archive = "
81-
T: rkyv::Archive,
82-
R: rkyv::Archive,
83-
Translation<T, D>: rkyv::Archive<Archived = Translation<T::Archived, D>>
84-
")
77+
rkyv(as = Isometry<T::Archived, R::Archived, D>,
78+
archive_bounds(
79+
T: rkyv::Archive,
80+
R: rkyv::Archive,
81+
Translation<T, D>: rkyv::Archive<Archived = Translation<T::Archived, D>>
82+
)
8583
)
8684
)]
8785
pub struct Isometry<T, R, const D: usize> {

src/geometry/orthographic.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,13 @@ use rkyv::bytecheck;
2525
#[cfg_attr(
2626
feature = "rkyv-serialize-no-std",
2727
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize),
28-
archive(
29-
as = "Orthographic3<T::Archived>",
30-
bound(archive = "
31-
T: rkyv::Archive,
32-
Matrix4<T>: rkyv::Archive<Archived = Matrix4<T::Archived>>
33-
")
28+
rkyv(as = Orthographic3<T::Archived>,
29+
archive_bounds(
30+
T: rkyv::Archive,
31+
Matrix4<T>: rkyv::Archive<Archived = Matrix4<T::Archived>>
32+
)
3433
)
3534
)]
36-
#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))]
3735
#[derive(Copy, Clone)]
3836
pub struct Orthographic3<T> {
3937
matrix: Matrix4<T>,

src/geometry/perspective.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,20 @@ use crate::base::{Matrix4, Vector, Vector3};
1919
use crate::geometry::{Point3, Projective3};
2020

2121
#[cfg(feature = "rkyv-serialize")]
22-
use rkyv::bytecheck;
22+
use rkyv::{bytecheck, rancor};
2323

2424
/// A 3D perspective projection stored as a homogeneous 4x4 matrix.
2525
#[repr(C)]
2626
#[cfg_attr(
2727
feature = "rkyv-serialize-no-std",
2828
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize),
29-
archive(
30-
as = "Perspective3<T::Archived>",
31-
bound(archive = "
32-
T: rkyv::Archive,
33-
Matrix4<T>: rkyv::Archive<Archived = Matrix4<T::Archived>>
34-
")
29+
rkyv(as = Perspective3<T::Archived>,
30+
archive_bounds(
31+
T: rkyv::Archive,
32+
Matrix4<T>: rkyv::Archive<Archived = Matrix4<T::Archived>>
33+
)
3534
)
3635
)]
37-
#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))]
3836
#[derive(Copy, Clone)]
3937
pub struct Perspective3<T> {
4038
matrix: Matrix4<T>,

0 commit comments

Comments
 (0)