table/table/
serde.rs

1// Copyright (C) 2018  Project Tsukurou!
2//
3// This program is free software: you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation, either version 3 of the License, or
6// (at your option) any later version.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with this program.  If not, see <https://www.gnu.org/licenses/>.
15
16use std::collections::HashMap;
17
18use serde::{Serialize, Serializer, Deserialize, Deserializer};
19
20use table::Table;
21
22impl Serialize for Table {
23    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
24    where
25        S: Serializer,
26    {
27        self.map.serialize(serializer)
28    }
29}
30
31impl<'de> Deserialize<'de> for Table {
32    fn deserialize<D>(deserializer: D) -> Result<Table, D::Error>
33    where
34        D: Deserializer<'de>,
35    {
36        Ok(Table {
37            map: HashMap::deserialize(deserializer)?,
38        })
39    }
40}