src/loc.rs

branch
dev
changeset 86
d5b0e496b72f
parent 64
4f6ca107ccb1
--- a/src/loc.rs	Mon Dec 30 15:46:28 2024 -0500
+++ b/src/loc.rs	Mon Jan 06 20:29:25 2025 -0500
@@ -13,14 +13,18 @@
 use crate::linops::{AXPY, Mapping, Linear};
 use crate::instance::{Instance, BasicDecomposition};
 use crate::mapping::Space;
-use serde::ser::{Serialize, Serializer, SerializeSeq};
+use serde::{Serialize, Deserialize};
 
 
 /// A container type for (short) `N`-dimensional vectors of element type `F`.
 ///
 /// Supports basic operations of an [`Euclidean`] space, several [`Norm`]s, and
 /// fused [`AXPY`] operations, among others.
-#[derive(Copy,Clone,Debug,PartialEq,Eq)]
+#[derive(Copy,Clone,Debug,PartialEq,Eq,Serialize,Deserialize)]
+#[serde(bound(
+    serialize = "[F; N] : Serialize",
+    deserialize = "[F; N] : for<'a> Deserialize<'a>"
+))]
 pub struct Loc<F, const N : usize>(
     /// An array of the elements of the vector
     pub [F; N]
@@ -39,23 +43,6 @@
     }
 }
 
-// Need to manually implement as [F; N] serialisation is provided only for some N.
-impl<F, const N : usize> Serialize for Loc<F, N>
-where
-    F: Serialize,
-{
-    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
-    where
-        S: Serializer,
-    {
-        let mut seq = serializer.serialize_seq(Some(N))?;
-        for e in self.iter() {
-            seq.serialize_element(e)?;
-        }
-        seq.end()
-    }
-}
-
 impl<F, const N : usize> Loc<F, N> {
     /// Creates a new `Loc` vector from an array.
     #[inline]

mercurial