gd_rs/
traits.rs

1pub trait GDProperty {
2    fn as_gd_string(&self) -> String;
3    fn from_gd_string(value: &String) -> Self;
4}
5
6pub trait GDBool {
7    // Takes str 0/1 and converts into bool
8    fn from_str(text: &str) -> bool;
9}
10
11impl GDBool for bool {
12    fn from_str(text: &str) -> bool {
13        if text == "1" {
14            return true;
15        }
16        
17        return false;
18    }
19}
20
21impl GDProperty for bool {
22    fn as_gd_string(&self) -> String {
23        if *self == true {
24            return "1".to_string();
25        }
26        return "0".to_string();
27    }
28    
29    fn from_gd_string(value: &String) -> Self {
30        if value == "1" {
31            return true;
32        }
33        return false;
34    }
35}
36impl GDProperty for f32 {
37    fn as_gd_string(&self) -> String {
38        self.to_string()
39    }
40    
41    fn from_gd_string(value: &String) -> Self {
42        value.parse::<f32>().unwrap()
43    }
44}
45
46
47impl GDProperty for u16 {
48    fn as_gd_string(&self) -> String {
49        self.to_string()
50    }
51    
52    fn from_gd_string(value: &String) -> Self {
53        value.parse::<u16>().unwrap()
54    }
55}
56
57impl GDProperty for String {
58    fn as_gd_string(&self) -> String {
59        self.clone()
60    }
61
62    fn from_gd_string(value: &String) -> Self {
63        value.clone()
64    }
65}