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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
use std::collections::vec_deque::Iter;
use std::collections::vec_deque::IntoIter;
use std::collections::VecDeque;
#[derive(Debug,Clone)]
pub struct Actions<T>(VecDeque<T>);
impl<T> ::std::default::Default for Actions<T> {
fn default() -> Self {
Self(VecDeque::new())
}
}
impl<T> ::std::cmp::PartialEq for Actions<T>
where
T: PartialEq,
{
fn eq(&self, other: &Actions<T>) -> bool {
let local_actions = &self.0;
let other_actions = &other.0;
if local_actions.len() != other_actions.len() {
return false;
}
for (idx, action) in local_actions.iter().enumerate() {
if action != &other_actions[idx] {
return false;
}
}
true
}
}
impl<T> Actions<T> {
pub fn add_all(&mut self,items: Vec<T>) {
for item in items.into_iter() {
self.push(item);
}
}
pub fn push(&mut self, action: T) {
self.0.push_back(action);
}
pub fn push_once(&mut self, action: T)
where
T: PartialEq,
{
let mut found = false;
for local_action in self.0.iter() {
if local_action == &action {
found = true;
break;
}
}
if !found {
self.0.push_back(action);
}
}
pub fn pop_front(&mut self) -> Option<T> {
self.0.pop_front()
}
pub fn count(&self) -> usize {
self.0.len()
}
pub fn iter<'a>(&'a self) -> Iter<'a, T> {
self.0.iter()
}
pub fn into_iter(self) -> IntoIter<T> {
self.0.into_iter()
}
}
impl <T>From<Vec<T>> for Actions<T> {
fn from(vec: Vec<T>) -> Self {
let mut actions = Self::default();
for item in vec.into_iter() {
actions.push(item);
}
actions
}
}