use super::Handler;
use crate::{error, path::Path, streamer::Token};
use std::{any::Any, str::FromStr};
#[derive(Debug)]
pub struct Replace {
new_data: Vec<u8>,
}
impl Replace {
pub fn new(new_data: Vec<u8>) -> Self {
Self { new_data }
}
}
impl FromStr for Replace {
type Err = error::Handler;
fn from_str(input: &str) -> Result<Self, Self::Err> {
Ok(Self::new(input.to_string().into_bytes()))
}
}
impl Handler for Replace {
fn end(
&mut self,
_path: &Path,
_matcher_idx: usize,
_token: Token,
) -> Result<Option<Vec<u8>>, error::Handler> {
Ok(Some(self.new_data.clone()))
}
fn is_converter(&self) -> bool {
true
}
fn as_any(&self) -> &dyn Any {
self
}
}