remove static lifetime requirement

This commit is contained in:
KitsuneCafe 2024-02-01 16:09:28 -05:00
parent 72d23383d6
commit 8121a30b0c

View file

@ -12,21 +12,21 @@ pub trait AndThenParser<P> {
fn and_then(&mut self, parser: P) -> &Self; fn and_then(&mut self, parser: P) -> &Self;
} }
pub struct Parser { pub struct Parser<'a> {
steps: Vec<Box<dyn Parse>>, steps: Vec<&'a mut dyn Parse>,
} }
impl Parser { impl<'a> Parser<'a> {
pub fn new() -> Self { pub fn new() -> Self {
Parser { steps: Vec::new() } Parser { steps: Vec::new() }
} }
pub fn push<P: Parse + 'static>(&mut self, parser: P) { pub fn push<P: Parse>(&mut self, parser: &'a mut P) {
self.steps.push(Box::new(parser)); self.steps.push(parser);
} }
} }
impl Parse for Parser { impl<'a> Parse for Parser<'a> {
fn parse(&mut self, path: &str, src: &[u8], dst: &mut Vec<u8>) -> std::io::Result<()> { fn parse(&mut self, path: &str, src: &[u8], dst: &mut Vec<u8>) -> std::io::Result<()> {
let mut buf_1 = Vec::from(src); let mut buf_1 = Vec::from(src);
let mut buf_2 = Vec::from(dst.as_slice()); let mut buf_2 = Vec::from(dst.as_slice());