From bfb20374d4a4a651359e8bc409c6e642fec736a8 Mon Sep 17 00:00:00 2001 From: KitsuneCafe <10284516+kitsunecafe@users.noreply.github.com> Date: Mon, 5 Feb 2024 04:18:56 -0500 Subject: [PATCH] parse convert --- src/roxy.rs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/roxy.rs b/src/roxy.rs index bd80992..f7f6f0d 100644 --- a/src/roxy.rs +++ b/src/roxy.rs @@ -6,18 +6,23 @@ use std::{ use crate::error::Error; -pub trait Parse { - fn parse(&mut self, path: &str, src: &[u8], dst: &mut Vec) -> Result<(), Error>; +pub trait AsParse { + 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 AsParse for P { + fn as_parse(&self) -> &dyn Parse { + self + } + + fn as_parse_mut(&mut self) -> &mut dyn Parse { self } } -impl Into> for (P,) { - fn into(self) -> Box { - Box::new(self.0) - } +pub trait Parse { + fn parse(&mut self, path: &str, src: &[u8], dst: &mut Vec) -> Result<(), Error>; } pub struct Parser<'a> { @@ -29,8 +34,8 @@ impl<'a> Parser<'a> { Parser { steps: Vec::new() } } - pub fn push>(&mut self, parser: P) { - self.steps.push(parser.into()); + pub fn push(&mut self, parser: &'a mut P) { + self.steps.push(parser.as_parse_mut()); } }