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
use crate::value::{Value};
use crate::metric::Metric;
use crate::types::*;
use easy_error::{Error, bail};
impl Value {
pub fn push_inplace(&mut self, value: Value) -> Result<&mut Value, Error> {
match self.dt {
LIST | RESULT => {
match &mut self.data {
Val::List(ref mut v) => {
let _ = v.push(value.clone());
}
_ => {
bail!("Invalid List format for push() operation");
}
}
return Ok(self);
}
QUEUE | FIFO => {
match &mut self.data {
Val::Queue(ref mut v) => {
let _ = v.push(value.clone());
}
_ => {
bail!("Invalid Queue/Fifo format for push() operation");
}
}
return Ok(self)
}
LAMBDA => {
match &mut self.data {
Val::Lambda(ref mut v) => {
let _ = v.push(value.clone());
}
_ => {
bail!("Invalid Lambda format for push() operation");
}
}
return Ok(self);
}
METRICS => {
if value.dt != FLOAT {
return Ok(self);
}
match &mut self.data {
Val::Metrics(ref mut v) => {
let _ = &v.push(Metric::new(value.cast_float().unwrap()));
let _ = &v.remove(0);
return Ok(self);
}
_ => {
bail!("Invalid Metric format for push() operation");
}
}
}
_ => {
bail!("This Value do not support push() operation");
}
}
}
}