use std::{error::Error, fmt, io::{self, ErrorKind, Read, Write}, str}; #[derive(Default, Clone, Copy)] pub enum Style { #[default] Plain, Spaces, Prefixed, Table, } #[derive(Debug)] pub struct ParseStyleError; impl fmt::Display for ParseStyleError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{self:?}") } } impl Error for ParseStyleError {} impl str::FromStr for Style { type Err = ParseStyleError; fn from_str(s: &str) -> Result { match s { "plain" => Ok(Self::Plain), "spaces" => Ok(Self::Spaces), "prefixed" => Ok(Self::Prefixed), "table" => Ok(Self::Table), _ => Err(ParseStyleError), } } } pub struct Encoder { reader: R, writer: W, style: Style, wrap: Option, } impl Encoder { pub fn new(reader: R, writer: W, style: Option