File: ser_xor_de.rs

package info (click to toggle)
rust-serde-big-array 0.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 144 kB
  • sloc: makefile: 2
file content (38 lines) | stat: -rw-r--r-- 737 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#![no_std]

use serde_big_array::BigArray;
use serde_derive::{Deserialize, Serialize};

#[derive(Serialize)]
struct S {
    #[serde(with = "BigArray")]
    arr: [SerOnly; 64],
}

#[derive(Debug, Clone, Copy, Serialize)]
struct SerOnly(u8);

#[derive(Deserialize)]
struct D {
    #[serde(with = "BigArray")]
    arr: [DeOnly; 64],
}

#[derive(Debug, Clone, Copy, Deserialize)]
struct DeOnly(u8);

impl PartialEq<DeOnly> for SerOnly {
    fn eq(&self, other: &DeOnly) -> bool {
        self.0 == other.0
    }
}

#[test]
fn test() {
    let s = S {
        arr: [SerOnly(1); 64],
    };
    let j = serde_json::to_string(&s).unwrap();
    let s_back = serde_json::from_str::<D>(&j).unwrap();
    assert_eq!(&s.arr[..], &s_back.arr[..]);
}