melib: move Sort{Order,Field} to utils mod

We want to use SortOrder enum for non-thread purposes in the next
commit, so move it out of the thread module.

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
pull/284/head
Manos Pitsidianakis 2023-08-21 12:38:53 +03:00
parent 52874f9a97
commit a1e7006186
Signed by: Manos Pitsidianakis
GPG Key ID: 7729C7707F7E09D0
12 changed files with 63 additions and 55 deletions

View File

@ -22,7 +22,6 @@
//! A parser module for user commands passed through
//! [`Command`](crate::types::UIMode::Command) mode.
pub use melib::thread::{SortField, SortOrder};
use melib::{
nom::{
self,
@ -35,7 +34,7 @@ use melib::{
sequence::{pair, preceded, separated_pair},
IResult,
},
Error,
Error, SortField, SortOrder,
};
use crate::melib::parser::BytesExt;

View File

@ -23,8 +23,7 @@
use std::path::PathBuf;
use melib::email::mailto::Mailto;
pub use melib::thread::{SortField, SortOrder};
use melib::{email::mailto::Mailto, SortField, SortOrder};
use crate::components::{Component, ComponentId};

View File

@ -31,7 +31,7 @@ use std::{
process::{Command, Stdio},
};
use melib::{backends::TagHash, search::Query, StderrLogger};
use melib::{backends::TagHash, search::Query, SortField, SortOrder, StderrLogger};
use crate::{conf::deserializers::non_empty_opt_string, terminal::Color};
@ -61,7 +61,6 @@ use std::{
};
use indexmap::IndexMap;
pub use melib::thread::{SortField, SortOrder};
use melib::{
conf::{AccountSettings, MailboxConf, ToggleFlag},
error::*,

View File

@ -47,8 +47,8 @@ use melib::{
error::{Error, ErrorKind, Result},
log,
text_processing::GlobMatch,
thread::{SortField, SortOrder, Threads},
AddressBook, Collection, LogLevel,
thread::Threads,
AddressBook, Collection, LogLevel, SortField, SortOrder,
};
use smallvec::SmallVec;

View File

@ -22,7 +22,7 @@
use std::{cmp, collections::BTreeMap, convert::TryInto, iter::FromIterator};
use indexmap::IndexSet;
use melib::{TagHash, Threads};
use melib::{SortField, SortOrder, TagHash, Threads};
use super::*;
use crate::{components::PageMovement, jobs::JoinHandle};

View File

@ -22,7 +22,7 @@
use std::{collections::BTreeMap, iter::FromIterator};
use indexmap::IndexSet;
use melib::{TagHash, Threads, UnixTimestamp};
use melib::{SortField, SortOrder, TagHash, Threads, UnixTimestamp};
use super::*;
use crate::{components::PageMovement, jobs::JoinHandle};

View File

@ -21,7 +21,7 @@
use std::{cmp, iter::FromIterator};
use melib::{Address, ThreadNode};
use melib::{Address, SortField, SortOrder, ThreadNode};
use super::{EntryStrings, *};
use crate::{components::PageMovement, jobs::JoinHandle};

View File

@ -21,7 +21,7 @@
use std::{cmp, convert::TryInto, iter::FromIterator};
use melib::{ThreadNode, Threads};
use melib::{SortField, SortOrder, ThreadNode, Threads};
use super::*;
use crate::components::PageMovement;

View File

@ -33,9 +33,8 @@ use melib::{
escape_double_quote,
Query::{self, *},
},
thread::{SortField, SortOrder},
utils::sqlite3::{self as melib_sqlite3, rusqlite::params, DatabaseDescription},
Error, Result,
Error, Result, SortField, SortOrder,
};
use smallvec::SmallVec;

View File

@ -134,6 +134,7 @@ pub mod text_processing;
pub use utils::{
datetime::UnixTimestamp,
logging::{LogLevel, StderrLogger},
SortField, SortOrder,
};
pub mod addressbook;

View File

@ -35,7 +35,7 @@
use crate::{
email::{address::StrBuild, parser::BytesExt, *},
UnixTimestamp,
SortField, SortOrder, UnixTimestamp,
};
mod iterators;
@ -44,8 +44,6 @@ use std::{
collections::{HashMap, HashSet, VecDeque},
iter::FromIterator,
ops::Index,
result::Result as StdResult,
str::FromStr,
string::ToString,
sync::{Arc, RwLock},
};
@ -467,44 +465,6 @@ impl SubjectPrefix for &str {
}
}
/* Sorting states. */
#[derive(Debug, Default, Clone, PartialEq, Eq, Copy, Deserialize, Serialize)]
pub enum SortOrder {
Asc,
#[default]
Desc,
}
#[derive(Debug, Default, Clone, PartialEq, Eq, Copy, Deserialize, Serialize)]
pub enum SortField {
Subject,
#[default]
Date,
}
impl FromStr for SortField {
type Err = ();
fn from_str(s: &str) -> StdResult<Self, Self::Err> {
match s.trim() {
"subject" | "s" | "sub" | "sbj" | "subj" => Ok(Self::Subject),
"date" | "d" => Ok(Self::Date),
_ => Err(()),
}
}
}
impl FromStr for SortOrder {
type Err = ();
fn from_str(s: &str) -> StdResult<Self, Self::Err> {
match s.trim() {
"asc" => Ok(Self::Asc),
"desc" => Ok(Self::Desc),
_ => Err(()),
}
}
}
#[derive(Default, Clone, Debug, Deserialize, Serialize)]
pub struct Thread {
pub root: ThreadNodeHash,

View File

@ -92,6 +92,8 @@ pub mod html_escape {
}
}
use std::str::FromStr;
#[macro_export]
macro_rules! declare_u64_hash {
($type_name:ident) => {
@ -155,3 +157,52 @@ macro_rules! declare_u64_hash {
}
};
}
/* Sorting states. */
#[derive(Debug, Default, Clone, PartialEq, Eq, Copy, Deserialize, Serialize)]
pub enum SortOrder {
Asc,
#[default]
Desc,
}
#[derive(Debug, Default, Clone, PartialEq, Eq, Copy, Deserialize, Serialize)]
pub enum SortField {
Subject,
#[default]
Date,
}
impl FromStr for SortField {
type Err = ();
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
match s.trim().to_ascii_lowercase().as_str() {
"subject" | "s" | "sub" | "sbj" | "subj" => Ok(Self::Subject),
"date" | "d" => Ok(Self::Date),
_ => Err(()),
}
}
}
impl FromStr for SortOrder {
type Err = ();
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
match s.trim().to_ascii_lowercase().as_str() {
"asc" => Ok(Self::Asc),
"desc" => Ok(Self::Desc),
_ => Err(()),
}
}
}
impl std::ops::Not for SortOrder {
type Output = Self;
fn not(self) -> Self::Output {
match self {
Self::Asc => Self::Desc,
Self::Desc => Self::Asc,
}
}
}