Im trying to serialize a fixed array of data (a struct) inside another struct.
both struct derive Serialize, Deserialize from Serde lib. but im getting errors with the second struct, saying the trait bound
[Acceleration; 300]: Serialize is not satisfied
use serde_json;
use serde::{Serialize, Deserialize};
use std::fs::File;
use std::path::Path;
use std::io::{Read, Write, Result, Error, ErrorKind};
mod utils;
trait MPU60X0Data {
fn saveData(&self, file_name: &str) -> Result<()>;
fn loadData(&self, file_name: &str) -> Result<()>;
}
#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct Acceleration {
x: f32,
y: f32,
z: f32,
}
#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct Gyroscope {
x: f32,
y: f32,
z: f32,
}
// 5 entries every second for 1 minute
const NUMBER_OF_ENTRIES_PER_MIN : usize = 5 * 60;
#[derive(Deserialize, Serialize, PartialEq, Debug)]
struct Data {
accelerations : [Acceleration; NUMBER_OF_ENTRIES_PER_MIN],
gyroscope_angles: [Gyroscope; NUMBER_OF_ENTRIES_PER_MIN],
}
impl MPU60X0Data for Data {
fn saveData(&self, file_name: &str) -> Result<()> {
if utils::path_exists(&file_name) {
Error::new(ErrorKind::AlreadyExists ,"The specified file exist and cannot be mofiled.");
}
Ok(())
}
fn loadData(&self, file_name: &str) -> Result<()> {
todo!()
}
}
and im getting errors like this on build
error[E0277]: the trait bound `[Acceleration; 300]: Deserialize<'_>` is not satisfied
--> src\main.rs:35:21
|
35 | accelerations : [Acceleration; NUMBER_OF_ENTRIES_PER_MIN],
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Deserialize<'_>` is not implemented for `[Acceleration; 300]`
|
= help: the following other types implement trait `Deserialize<'de>`:
&'a [u8]
[T; 0]
[T; 10]
[T; 11]
[T; 12]
[T; 13]
[T; 14]
[T; 15]
and 26 others
note: required by a bound in `next_element`
--> C:\Users\Vasu\.cargo\registry\src\index.crates.io-6f17d22bba15001f\serde-1.0.164\src\de\mod.rs:1729:12
|
1729 | T: Deserialize<'de>,
| ^^^^^^^^^^^^^^^^ required by this bound in `SeqAccess::next_element`
error[E0277]: the trait bound `[Gyroscope; 300]: Deserialize<'_>` is not satisfied
--> src\main.rs:36:23
|
36 | gyroscope_angles: [Gyroscope; NUMBER_OF_ENTRIES_PER_MIN],
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Deserialize<'_>` is not implemented for `[Gyroscope; 300]`
|
= help: the following other types implement trait `Deserialize<'de>`:
&'a [u8]
[T; 0]
[T; 10]
[T; 11]
[T; 12]
[T; 13]
[T; 14]
[T; 15]
and 26 others
note: required by a bound in `next_element`
--> C:\Users\Vasu\.cargo\registry\src\index.crates.io-6f17d22bba15001f\serde-1.0.164\src\de\mod.rs:1729:12
|
1729 | T: Deserialize<'de>,
| ^^^^^^^^^^^^^^^^ required by this bound in `SeqAccess::next_element`
error[E0277]: the trait bound `[Acceleration; 300]: Deserialize<'_>` is not satisfied
--> src\main.rs:35:21
|
35 | accelerations : [Acceleration; NUMBER_OF_ENTRIES_PER_MIN],
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Deserialize<'_>` is not implemented for `[Acceleration; 300]`
|
= help: the following other types implement trait `Deserialize<'de>`:
&'a [u8]
[T; 0]
[T; 10]
[T; 11]
[T; 12]
[T; 13]
[T; 14]
[T; 15]
and 26 others
note: required by a bound in `next_value`
--> C:\Users\Vasu\.cargo\registry\src\index.crates.io-6f17d22bba15001f\serde-1.0.164\src\de\mod.rs:1868:12
|
1868 | V: Deserialize<'de>,
| ^^^^^^^^^^^^^^^^ required by this bound in `MapAccess::next_value`
error[E0277]: the trait bound `[Gyroscope; 300]: Deserialize<'_>` is not satisfied
--> src\main.rs:36:23
|
36 | gyroscope_angles: [Gyroscope; NUMBER_OF_ENTRIES_PER_MIN],
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Deserialize<'_>` is not implemented for `[Gyroscope; 300]`
|
= help: the following other types implement trait `Deserialize<'de>`:
&'a [u8]
[T; 0]
[T; 10]
[T; 11]
[T; 12]
[T; 13]
[T; 14]
[T; 15]
and 26 others
note: required by a bound in `next_value`
--> C:\Users\Vasu\.cargo\registry\src\index.crates.io-6f17d22bba15001f\serde-1.0.164\src\de\mod.rs:1868:12
|
1868 | V: Deserialize<'de>,
| ^^^^^^^^^^^^^^^^ required by this bound in `MapAccess::next_value`
error[E0277]: the trait bound `[Acceleration; 300]: Deserialize<'_>` is not satisfied
--> src\main.rs:35:5
|
35 | accelerations : [Acceleration; NUMBER_OF_ENTRIES_PER_MIN],
| ^^^^^^^^^^^^^ the trait `Deserialize<'_>` is not implemented for `[Acceleration; 300]`
|
= help: the following other types implement trait `Deserialize<'de>`:
&'a [u8]
[T; 0]
[T; 10]
[T; 11]
[T; 12]
[T; 13]
[T; 14]
[T; 15]
and 26 others
note: required by a bound in `_::_serde::__private::de::missing_field`
--> C:\Users\Vasu\.cargo\registry\src\index.crates.io-6f17d22bba15001f\serde-1.0.164\src\private\de.rs:22:8
|
22 | V: Deserialize<'de>,
| ^^^^^^^^^^^^^^^^ required by this bound in `missing_field`
error[E0277]: the trait bound `[Gyroscope; 300]: Deserialize<'_>` is not satisfied
--> src\main.rs:36:5
|
36 | gyroscope_angles: [Gyroscope; NUMBER_OF_ENTRIES_PER_MIN],
| ^^^^^^^^^^^^^^^^ the trait `Deserialize<'_>` is not implemented for `[Gyroscope; 300]`
|
= help: the following other types implement trait `Deserialize<'de>`:
&'a [u8]
[T; 0]
[T; 10]
[T; 11]
[T; 12]
[T; 13]
[T; 14]
[T; 15]
and 26 others
note: required by a bound in `_::_serde::__private::de::missing_field`
--> C:\Users\Vasu\.cargo\registry\src\index.crates.io-6f17d22bba15001f\serde-1.0.164\src\private\de.rs:22:8
|
22 | V: Deserialize<'de>,
| ^^^^^^^^^^^^^^^^ required by this bound in `missing_field`
error[E0277]: the trait bound `[Acceleration; 300]: Serialize` is not satisfied
--> src\main.rs:33:23
|
33 | #[derive(Deserialize, Serialize, PartialEq, Debug)]
| ^^^^^^^^^ the trait `Serialize` is not implemented for `[Acceleration; 300]`
34 | struct Data {
35 | accelerations : [Acceleration; NUMBER_OF_ENTRIES_PER_MIN],
| ------------- required by a bound introduced by this call
|
= help: the following other types implement trait `Serialize`:
[T; 0]
[T; 10]
[T; 11]
[T; 12]
[T; 13]
[T; 14]
[T; 15]
[T; 16]
and 26 others
note: required by a bound in `_::_serde::ser::SerializeStruct::serialize_field`
--> C:\Users\Vasu\.cargo\registry\src\index.crates.io-6f17d22bba15001f\serde-1.0.164\src\ser\mod.rs:1901:12
|
1901 | T: Serialize;
| ^^^^^^^^^ required by this bound in `SerializeStruct::serialize_field`
error[E0277]: the trait bound `[Gyroscope; 300]: Serialize` is not satisfied
--> src\main.rs:33:23
|
33 | #[derive(Deserialize, Serialize, PartialEq, Debug)]
| ^^^^^^^^^ the trait `Serialize` is not implemented for `[Gyroscope; 300]`
...
36 | gyroscope_angles: [Gyroscope; NUMBER_OF_ENTRIES_PER_MIN],
| ---------------- required by a bound introduced by this call
|
= help: the following other types implement trait `Serialize`:
[T; 0]
[T; 10]
[T; 11]
[T; 12]
[T; 13]
[T; 14]
[T; 15]
[T; 16]
and 26 others
note: required by a bound in `_::_serde::ser::SerializeStruct::serialize_field`
--> C:\Users\Vasu\.cargo\registry\src\index.crates.io-6f17d22bba15001f\serde-1.0.164\src\ser\mod.rs:1901:12
|
1901 | T: Serialize;
| ^^^^^^^^^ required by this bound in `SerializeStruct::serialize_field`