Compare commits
No commits in common. "7839db8b062698adfe81a86d2a0cf041a6711456" and "4d50a1d2870245dfae18a48b984cbccaa2183cd4" have entirely different histories.
7839db8b06
...
4d50a1d287
59
src/roxy.rs
59
src/roxy.rs
|
@ -6,25 +6,20 @@ use std::{
|
|||
|
||||
use crate::error::Error;
|
||||
|
||||
pub trait AsParse {
|
||||
fn as_parse(&self) -> &dyn Parse;
|
||||
fn as_parse_mut(&mut self) -> &mut dyn Parse;
|
||||
}
|
||||
|
||||
impl<P: Parse> AsParse for P {
|
||||
fn as_parse(&self) -> &dyn Parse {
|
||||
self
|
||||
}
|
||||
|
||||
fn as_parse_mut(&mut self) -> &mut dyn Parse {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Parse: AsParse {
|
||||
pub trait Parse {
|
||||
fn parse(&mut self, path: &str, src: &[u8], dst: &mut Vec<u8>) -> Result<(), Error>;
|
||||
}
|
||||
|
||||
impl<'a, P: Parse + 'static> Into<Box<dyn Parse>> for (P,) {
|
||||
fn into(self) -> Box<dyn Parse> {
|
||||
Box::new(self.0)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait AndThenParser<P> {
|
||||
fn and_then(&mut self, parser: P) -> &Self;
|
||||
}
|
||||
|
||||
pub struct Parser<'a> {
|
||||
steps: Vec<&'a mut dyn Parse>,
|
||||
}
|
||||
|
@ -34,12 +29,8 @@ impl<'a> Parser<'a> {
|
|||
Parser { steps: Vec::new() }
|
||||
}
|
||||
|
||||
pub fn push<P: AsParse>(&mut self, parser: &'a mut P) {
|
||||
self.steps.push(parser.as_parse_mut());
|
||||
}
|
||||
|
||||
pub fn append(&mut self, parsers: &mut Vec<&'a mut dyn Parse>) {
|
||||
self.steps.append(parsers);
|
||||
pub fn push<P: Into<&'a mut dyn Parse>>(&mut self, parser: P) {
|
||||
self.steps.push(parser.into());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -145,27 +136,3 @@ impl Roxy {
|
|||
Self::mkdir_and_open(&output).and_then(|mut f| f.write_all(&buf))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{Parse, Parser};
|
||||
|
||||
struct TestParser;
|
||||
impl TestParser {
|
||||
pub fn new() -> Self {
|
||||
Self
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for TestParser {
|
||||
fn parse(
|
||||
&mut self,
|
||||
path: &str,
|
||||
src: &[u8],
|
||||
dst: &mut Vec<u8>,
|
||||
) -> Result<(), crate::error::Error> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue