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
use crate::value::Value;
use crate::types::*;
impl Value {
pub fn export_float(&self) -> Result<Vec<f64>, Box<dyn std::error::Error>> {
match &self.data {
Val::F64(f_val) => {
return Result::Ok(vec![*f_val]);
}
Val::I64(i_val) => {
return Result::Ok(vec![*i_val as f64]);
}
Val::List(l_val) => {
let mut res: Vec<f64> = Vec::new();
for n in l_val {
match n.dt {
FLOAT => {
match n.cast_float() {
Ok(f_val) => res.push(f_val),
_ => {},
}
}
INTEGER => {
match n.cast_int() {
Ok(i_val) => res.push(i_val as f64),
_ => {},
}
}
_ => {},
}
}
return Result::Ok(res);
}
Val::Metrics(m_val) => {
let mut res: Vec<f64> = Vec::new();
for m in m_val {
res.push(m.data as f64);
}
return Result::Ok(res);
}
_ => return Err("This Dynamic type is not float".into()),
}
}
}