mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-22 23:31:05 +00:00
26 lines
544 B
Rust
26 lines
544 B
Rust
use anyhow::bail;
|
|
use serde::Deserialize;
|
|
|
|
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Eq)]
|
|
#[serde(try_from = "String")]
|
|
pub enum SortBy {
|
|
#[default]
|
|
Alphabetical,
|
|
Created,
|
|
Modified,
|
|
Size,
|
|
}
|
|
|
|
impl TryFrom<String> for SortBy {
|
|
type Error = anyhow::Error;
|
|
|
|
fn try_from(s: String) -> Result<Self, Self::Error> {
|
|
Ok(match s.as_str() {
|
|
"alphabetical" => Self::Alphabetical,
|
|
"created" => Self::Created,
|
|
"modified" => Self::Modified,
|
|
"size" => Self::Size,
|
|
_ => bail!("invalid sort_by value: {s}"),
|
|
})
|
|
}
|
|
}
|