yazi/yazi-config/src/priority.rs
2023-12-29 22:37:43 +08:00

32 lines
634 B
Rust

use std::str::FromStr;
use anyhow::anyhow;
use serde::Deserialize;
#[derive(Default, Clone, Copy, Debug, Deserialize)]
#[serde(try_from = "String")]
pub enum Priority {
Low = 0,
#[default]
Normal = 1,
High = 2,
}
impl FromStr for Priority {
type Err = anyhow::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"low" => Ok(Self::Low),
"normal" => Ok(Self::Normal),
"high" => Ok(Self::High),
_ => Err(anyhow!("Invalid priority: {s}")),
}
}
}
impl TryFrom<String> for Priority {
type Error = anyhow::Error;
fn try_from(s: String) -> Result<Self, Self::Error> { Self::from_str(&s) }
}