parse convert
This commit is contained in:
parent
36530dc69a
commit
bfb20374d4
23
src/roxy.rs
23
src/roxy.rs
|
@ -6,18 +6,23 @@ use std::{
|
||||||
|
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
|
|
||||||
pub trait Parse {
|
pub trait AsParse {
|
||||||
fn parse(&mut self, path: &str, src: &[u8], dst: &mut Vec<u8>) -> Result<(), Error>;
|
fn as_parse(&self) -> &dyn Parse;
|
||||||
|
fn as_parse_mut(&mut self) -> &mut dyn Parse;
|
||||||
|
}
|
||||||
|
|
||||||
fn as_dyn(&self) -> &dyn Parse where Self: Sized {
|
impl<P: Parse> AsParse for P {
|
||||||
|
fn as_parse(&self) -> &dyn Parse {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
fn as_parse_mut(&mut self) -> &mut dyn Parse {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P: Parse + 'static> Into<Box<dyn Parse>> for (P,) {
|
pub trait Parse {
|
||||||
fn into(self) -> Box<dyn Parse> {
|
fn parse(&mut self, path: &str, src: &[u8], dst: &mut Vec<u8>) -> Result<(), Error>;
|
||||||
Box::new(self.0)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Parser<'a> {
|
pub struct Parser<'a> {
|
||||||
|
@ -29,8 +34,8 @@ impl<'a> Parser<'a> {
|
||||||
Parser { steps: Vec::new() }
|
Parser { steps: Vec::new() }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn push<P: Into<&'a mut dyn Parse>>(&mut self, parser: P) {
|
pub fn push<P: AsParse>(&mut self, parser: &'a mut P) {
|
||||||
self.steps.push(parser.into());
|
self.steps.push(parser.as_parse_mut());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue