use core::{fmt, str::FromStr};
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub enum CutMode {
#[default]
Precise,
Full,
Search,
}
impl CutMode {
pub const ALL: &'static [CutMode] = &[CutMode::Precise, CutMode::Full, CutMode::Search];
pub const fn as_str(self) -> &'static str {
match self {
CutMode::Precise => "precise",
CutMode::Full => "full",
CutMode::Search => "search",
}
}
}
impl fmt::Display for CutMode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
impl FromStr for CutMode {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"precise" => Ok(CutMode::Precise),
"full" => Ok(CutMode::Full),
"search" => Ok(CutMode::Search),
_ => Err(()),
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct CutOption {
pub mode: CutMode,
pub keep_separator: bool,
}
impl CutOption {
pub const fn new(mode: CutMode) -> Self {
Self {
mode,
keep_separator: false,
}
}
pub const fn precise() -> Self {
Self::new(CutMode::Precise)
}
pub const fn full() -> Self {
Self::new(CutMode::Full)
}
pub const fn search() -> Self {
Self::new(CutMode::Search)
}
pub const fn with_separator(mut self) -> Self {
self.keep_separator = true;
self
}
}
impl From<CutMode> for CutOption {
fn from(mode: CutMode) -> Self {
Self::new(mode)
}
}