Newer
Older
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
39
40
41
use std::collections::HashMap;
use serde::Serialize;
use serde_derive::Serialize;
#[derive(Default, Serialize, Debug, Clone)]
pub struct Properties {
props: HashMap<String, Property>
}
impl Properties {
pub fn set(&mut self, name: &str, value: Property) -> Option<()> {
if self.props.insert(name.into(), value).is_some() {
Some(())
} else {
None
}
}
pub fn get(&self, name: &str) -> Option<&Property> {
self.props.get(name.into())
}
}
#[derive(Debug, Clone)]
pub struct Property {
pub prop: Proptype
}
impl Serialize for Property {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer {
serializer.serialize_newtype_struct("hallo", &self.prop)
}
}
#[non_exhaustive]
#[derive(Serialize, Debug, Clone)]
pub enum Proptype {
String(String),
I32(i32),
F64(f64)
}