Skip to main content

floria_plugin_sdk/data/expression/
conversions.rs

1use super::{super::super::dispatch_bindings::*, call::*, custom::*, list::*, map::*};
2
3use {duplicate::*, std::collections::*};
4
5impl From<List> for Expression {
6    fn from(list: List) -> Self {
7        Self::List(ListResource::new(list))
8    }
9}
10
11impl From<Map> for Expression {
12    fn from(map: Map) -> Self {
13        Self::Map(MapResource::new(map))
14    }
15}
16
17impl From<Custom> for Expression {
18    fn from(custom: Custom) -> Self {
19        Self::Custom(CustomResource::new(custom))
20    }
21}
22
23impl From<Call> for Expression {
24    fn from(call: Call) -> Self {
25        Self::Call(CallResource::new(call))
26    }
27}
28
29// Conversion from primitives
30
31impl From<()> for Expression {
32    fn from(_null: ()) -> Self {
33        Self::Null
34    }
35}
36
37#[duplicate_item(
38  FromT;
39  [i64];
40  [i32];
41  [i16];
42  [i8];
43  [isize];
44)]
45impl From<FromT> for Expression {
46    fn from(integer: FromT) -> Self {
47        Self::Integer(integer as i64)
48    }
49}
50
51#[duplicate_item(
52  FromT;
53  [u64];
54  [u32];
55  [u16];
56  [u8];
57  [usize];
58)]
59impl From<FromT> for Expression {
60    fn from(unsigned_integer: FromT) -> Self {
61        Self::UnsignedInteger(unsigned_integer as u64)
62    }
63}
64
65#[duplicate_item(
66  FromT;
67  [f64];
68  [f32];
69)]
70impl From<FromT> for Expression {
71    fn from(float: FromT) -> Self {
72        Self::Float(float as f64)
73    }
74}
75
76impl From<bool> for Expression {
77    fn from(boolean: bool) -> Self {
78        Self::Boolean(boolean)
79    }
80}
81
82impl From<String> for Expression {
83    fn from(string: String) -> Self {
84        Self::Text(string)
85    }
86}
87
88impl From<&str> for Expression {
89    fn from(string: &str) -> Self {
90        Self::Text(string.into())
91    }
92}
93
94impl From<Vec<u8>> for Expression {
95    fn from(bytes: Vec<u8>) -> Self {
96        Self::Blob(bytes)
97    }
98}
99
100impl From<&[u8]> for Expression {
101    fn from(bytes: &[u8]) -> Self {
102        Self::Blob(bytes.into())
103    }
104}
105
106impl From<Vec<Expression>> for Expression {
107    fn from(vector: Vec<Expression>) -> Self {
108        List::from(vector).into()
109    }
110}
111
112impl From<BTreeMap<Expression, Expression>> for Expression {
113    fn from(map: BTreeMap<Expression, Expression>) -> Self {
114        Map::from(map).into()
115    }
116}
117
118impl FromIterator<Expression> for Expression {
119    fn from_iter<IntoIteratorT>(iter: IntoIteratorT) -> Self
120    where
121        IntoIteratorT: IntoIterator<Item = Expression>,
122    {
123        List::from_iter(iter).into()
124    }
125}
126
127impl FromIterator<(Expression, Expression)> for Expression {
128    fn from_iter<IntoIteratorT>(iter: IntoIteratorT) -> Self
129    where
130        IntoIteratorT: IntoIterator<Item = (Expression, Expression)>,
131    {
132        Map::from_iter(iter).into()
133    }
134}