Impl FromStr for Style

This commit is contained in:
Nathan Fisher 2025-01-22 17:13:01 -05:00
parent 3ab6634661
commit ac01fe7b82

View file

@ -1,4 +1,4 @@
use std::io::{self, ErrorKind, Read, Write};
use std::{io::{self, ErrorKind, Read, Write}, str};
#[derive(Default, Clone, Copy)]
pub enum Style {
@ -9,6 +9,23 @@ pub enum Style {
Table,
}
#[derive(Debug)]
pub struct ParseStyleError;
impl str::FromStr for Style {
type Err = ParseStyleError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"plain" => Ok(Self::Plain),
"spaces" => Ok(Self::Spaces),
"prefixed" => Ok(Self::Prefixed),
"table" => Ok(Self::Table),
_ => Err(ParseStyleError),
}
}
}
pub struct Encoder<R: Read, W: Write> {
reader: R,
writer: W,