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
use std::collections::VecDeque;
use std::iter::{FromIterator,IntoIterator,Iterator};
use std::rc::Rc;
use super::Interceptor;
pub struct InterceptorQueue<E>(VecDeque<Rc<Box<Interceptor<Error = E>>>>);
impl<E> InterceptorQueue<E> {
pub fn push_back<T>(&mut self, value: T)
where T: Into<Rc<Box<Interceptor<Error = E>>>>,
{
self.0.push_back(value.into());
}
pub fn pop_front(&mut self) -> Option<Rc<Box<Interceptor<Error = E>>>> {
self.0.pop_front()
}
pub fn clear(&mut self) {
self.0.clear()
}
}
impl<E> FromIterator<Rc<Box<Interceptor<Error = E>>>> for InterceptorQueue<E> {
fn from_iter<T>(iter: T) -> InterceptorQueue<E>
where T: IntoIterator<Item = Rc<Box<Interceptor<Error = E>>>>
{
InterceptorQueue(iter.into_iter().collect())
}
}
impl<E> Extend<Box<Interceptor<Error = E>>> for InterceptorQueue<E> {
fn extend<T>(&mut self, iter: T)
where T: IntoIterator<Item = Box<Interceptor<Error = E>>>
{
self.0.extend(iter.into_iter().map(|i| Rc::new(i)))
}
}