Parse::as_dyn

This commit is contained in:
KitsuneCafe 2024-02-05 03:06:23 -05:00
parent 4d50a1d287
commit 36530dc69a

View file

@ -8,18 +8,18 @@ use crate::error::Error;
pub trait Parse { pub trait Parse {
fn parse(&mut self, path: &str, src: &[u8], dst: &mut Vec<u8>) -> Result<(), Error>; fn parse(&mut self, path: &str, src: &[u8], dst: &mut Vec<u8>) -> Result<(), Error>;
fn as_dyn(&self) -> &dyn Parse where Self: Sized {
self
}
} }
impl<'a, P: Parse + 'static> Into<Box<dyn Parse>> for (P,) { impl<P: Parse + 'static> Into<Box<dyn Parse>> for (P,) {
fn into(self) -> Box<dyn Parse> { fn into(self) -> Box<dyn Parse> {
Box::new(self.0) Box::new(self.0)
} }
} }
pub trait AndThenParser<P> {
fn and_then(&mut self, parser: P) -> &Self;
}
pub struct Parser<'a> { pub struct Parser<'a> {
steps: Vec<&'a mut dyn Parse>, steps: Vec<&'a mut dyn Parse>,
} }