Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::collections::{vec_deque, VecDeque};
- use std::fmt;
- use std;
- #[derive(Debug)]
- pub struct LimitedFifoQueue<T> {
- size: usize,
- store: VecDeque<T>,
- }
- impl<T> LimitedFifoQueue<T> where T: fmt::Display {
- pub fn new(size: usize) -> LimitedFifoQueue<T> {
- LimitedFifoQueue {
- size: size,
- store: VecDeque::with_capacity(size),
- }
- }
- pub fn push(&mut self, elem: T) {
- self.store.push_front(elem);
- if self.store.len() > self.size {
- self.store.pop_back();
- }
- }
- pub fn clear(&mut self) {
- self.store.clear();
- }
- }
- impl<T> IntoIterator for LimitedFifoQueue<T> where T: fmt::Display {
- type Item = T;
- type IntoIter = vec_deque::IntoIter<T>;
- fn into_iter(self) -> Self::IntoIter {
- self.store.into_iter()
- }
- }
- fn print_all<I>(lines: &I) where I: IntoIterator {
- for string in lines.into_iter() {
- println!("{}", string);
- }
- }
- fn print_all<I>(lines: I)
- where I: IntoIterator,
- I::Item: fmt::Display,
- {
- for string in lines.into_iter() {
- println!("{}", string);
- }
- }
- fn print_all<I>(lines: I)
- where I: IntoIterator,
- I::Item: fmt::Display,
- {
- for string in lines {
- println!("{}", string);
- }
- }
- fn print_all<I>(lines: &I) where I: IntoIterator {
- for string in lines.into_iter() {
- println!("{}", string);
- }
- }
- fn print_all<I>(lines: &I)
- where I: IntoIterator,
- I::Item: fmt::Display,
- { ... }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement