Closed vbarrielle closed 3 years ago
So the following diff fixes the issue:
diff --git a/src/sparse.rs b/src/sparse.rs
index c3fb133..0f86458 100644
--- a/src/sparse.rs
+++ b/src/sparse.rs
@@ -102,7 +102,7 @@ where
storage: CompressedStorage,
nrows: usize,
ncols: usize,
- #[cfg_attr(feature = "serde", serde(flatten))]
+ //#[cfg_attr(feature = "serde", serde(flatten))]
indptr: IndPtrBase<Iptr, IptrStorage>,
indices: IndStorage,
data: DataStorage,
Looks like flattening the IndPtrBase
is causing troubles, but I don't know why.
I've found a similar issue https://github.com/servo/bincode/issues/245
And according to https://github.com/servo/bincode/issues/167#issuecomment-653828999 this is not something we can be expecting a fix for.
Looks like we have two alternatives:
I'd really prefer the first solution.
Something I don't get though: by removing the flatten
attribute, serialization works, but I would expect the deserialization to fail since there should be one more level of structure. Or maybe that's not exposed with bincode.
And indeed, if I test a roundtrip with serde_json
without the flatten
attribute, there is an error because what's serialized is no longer what was expected.
Looks like there's only Serialize
that needs to be implemented manually.
I think we can cheat a little here and use the into
container attribute. I'll test this approach
Serde is tricky, and I'm not very familiar with these sorts of problems. https://serde.rs/container-attrs.html suggests using into
. I've tried this in https://github.com/mulimoen/sprs/tree/fix_serde_test, , but the requirement of Clone
, gives the following error messages:
A manual implementation might be the easiest next step
I've recently noticed that the test
tests/bincode_ser.rs
was not being executed. I fixed that to make it run in the fix_serde_test_branch, but it reveals there's an error at serialization time forCsMatView
: https://github.com/vbarrielle/sprs/runs/1581558055I've tried looking into it, but so far I don't get what's wrong, the serialization code is the same than for
CsVec
, where it works... @mulimoen you know that serialization code much better than I do, do you have an idea?