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
use alloc::boxed::Box; use alloc::vec::Vec; use core::slice; use super::reader::Reader; pub struct Readers<T> { vec: Vec<Box<Reader<T>>>, } impl<T> Readers<T> { #[inline(always)] pub fn new() -> Self { Readers { vec: Vec::new(), } } #[inline(always)] pub fn add<R: 'static + Reader<T>>(&mut self, reader: R) -> &mut Self { self.vec.push(Box::new(reader)); self } #[inline(always)] pub fn len(&mut self) -> usize { self.vec.len() } #[inline(always)] pub fn sort(&mut self) -> &mut Self { self.vec.sort_by(|a, b| a.priority().cmp(&b.priority())); self } #[inline(always)] pub fn iter(&mut self) -> slice::Iter<Box<Reader<T>>> { self.vec.iter() } }