tokio_interceptor/
queue.rs

1// This file is part of tokio-interceptor.
2//
3// tokio-interceptor is free software: you can redistribute it and/or modify
4// it under the terms of the GNU Lesser General Public License as published by
5// the Free Software Foundation, either version 3 of the License, or
6// (at your option) any later version.
7//
8// tokio-interceptor is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11// GNU Lesser General Public License for more details.
12//
13// You should have received a copy of the GNU Lesser General Public License
14// along with tokio-interceptor.  If not, see <http://www.gnu.org/licenses/>.
15
16use std::collections::VecDeque;
17use std::iter::{FromIterator,IntoIterator,Iterator};
18use std::rc::Rc;
19
20use super::Interceptor;
21
22pub struct InterceptorQueue<E>(VecDeque<Rc<Box<Interceptor<Error = E>>>>);
23
24impl<E> InterceptorQueue<E> {
25    pub fn push_back<T>(&mut self, value: T)
26    where T: Into<Rc<Box<Interceptor<Error = E>>>>,
27    {
28        self.0.push_back(value.into());
29    }
30
31    pub fn pop_front(&mut self) -> Option<Rc<Box<Interceptor<Error = E>>>> {
32        self.0.pop_front()
33    }
34
35    pub fn clear(&mut self) {
36        self.0.clear()
37    }
38}
39
40impl<E> FromIterator<Rc<Box<Interceptor<Error = E>>>> for InterceptorQueue<E> {
41    fn from_iter<T>(iter: T) -> InterceptorQueue<E>
42    where T: IntoIterator<Item = Rc<Box<Interceptor<Error = E>>>>
43    {
44        InterceptorQueue(iter.into_iter().collect())
45    }
46}
47
48impl<E> Extend<Box<Interceptor<Error = E>>> for InterceptorQueue<E> {
49    fn extend<T>(&mut self, iter: T)
50    where T: IntoIterator<Item = Box<Interceptor<Error = E>>>
51    {
52        self.0.extend(iter.into_iter().map(|i| Rc::new(i)))
53    }
54}