Skip to main content

rust_dynamic/
pull.rs

1use crate::value::{Value};
2use crate::types::*;
3
4impl Value {
5    pub fn pull(&self) -> Self {
6        match self.dt {
7            QUEUE => {
8                let mut data: Vec<Value> = Vec::new();
9                match &self.data {
10                    Val::Queue(v) => {
11                        if v.len() > 0 {
12                            for i in &v[1..] {
13                                data.push(i.clone());
14                            }
15                        }
16                    }
17                    _ => {},
18                }
19                return Value::to_queue(data);
20            }
21            FIFO => {
22                let mut data: Vec<Value> = Vec::new();
23                match &self.data {
24                    Val::Queue(v) => {
25                        if v.len() > 0 {
26                            for i in &v[..self.len()-1] {
27                                data.push(i.clone());
28                            }
29                        }
30                    }
31                    _ => {},
32                }
33                return Value::to_fifo(data);
34            }
35            LIST | RESULT => {
36                let mut data: Vec<Value> = Vec::new();
37                match &self.data {
38                    Val::List(v) => {
39                        for i in &v[..self.len()-1] {
40                            data.push(i.clone());
41                        }
42                    }
43                    _ => {},
44                }
45                if self.dt == LIST {
46                    return Value::from_list(data);
47                } else {
48                    return Value::to_result(data);
49                }
50            }
51            _ => {
52                let mut res = self.dup().unwrap();
53                res.regen_id();
54                return res;
55            }
56        }
57    }
58}