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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use std::collections::HashMap;
use Type;
pub trait SupportedType {
fn wrap(&self) -> Type;
}
impl SupportedType for () {
fn wrap(&self) -> Type { Type::None }
}
impl SupportedType for String {
fn wrap(&self) -> Type { Type::Text(self.clone()) }
}
impl SupportedType for bool {
fn wrap(&self) -> Type { Type::Switch(self.clone()) }
}
impl SupportedType for i32 {
fn wrap(&self) -> Type { Type::Int(self.clone()) }
}
impl SupportedType for f32 {
fn wrap(&self) -> Type { Type::Float(self.clone()) }
}
impl SupportedType for HashMap<String,Type> {
fn wrap(&self) -> Type { Type::Complex(self.clone()) }
}
impl SupportedType for Vec<Type> {
fn wrap(&self) -> Type { Type::Array(self.clone()) }
}
impl SupportedType for Type {
fn wrap(&self) -> Type { self.clone() }
}
impl<'a> SupportedType for &'a Type {
fn wrap(&self) -> Type {
match *self {
&Type::Text(ref inner) => Type::Text(inner.clone()),
&Type::Switch(ref inner) => Type::Switch(inner.clone()),
&Type::Int(ref inner) => Type::Int(inner.clone()),
&Type::Float(ref inner) => Type::Float(inner.clone()),
&Type::Array(ref inner) => Type::Array(inner.clone()),
&Type::Complex(ref inner) => Type::Complex(inner.clone()),
&Type::None => Type::None,
}
}
}
impl SupportedType for str {
fn wrap(&self) -> Type { Type::Text(self.to_string()) }
}
impl<'a> SupportedType for &'a str {
fn wrap(&self) -> Type { Type::Text(self.to_string()) }
}