use std::fmt;
use super::*;
use crate::sync::SyncDestination;
pub type FolderName = String;
pub type FoldersName = HashSet<FolderName>;
#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum FolderSyncHunk {
Create(FolderName, SyncDestination),
Cache(FolderName, SyncDestination),
Delete(FolderName, SyncDestination),
Uncache(FolderName, SyncDestination),
}
impl FolderSyncHunk {
pub fn is_left(&self) -> bool {
match self {
Self::Create(_, SyncDestination::Left) => true,
Self::Cache(_, SyncDestination::Left) => true,
Self::Delete(_, SyncDestination::Left) => true,
Self::Uncache(_, SyncDestination::Left) => true,
_ => false,
}
}
pub fn is_right(&self) -> bool {
match self {
Self::Create(_, SyncDestination::Right) => true,
Self::Cache(_, SyncDestination::Right) => true,
Self::Delete(_, SyncDestination::Right) => true,
Self::Uncache(_, SyncDestination::Right) => true,
_ => false,
}
}
pub fn folder(&self) -> &str {
match self {
Self::Create(folder, _) => folder.as_str(),
Self::Cache(folder, _) => folder.as_str(),
Self::Delete(folder, _) => folder.as_str(),
Self::Uncache(folder, _) => folder.as_str(),
}
}
}
impl fmt::Display for FolderSyncHunk {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Create(folder, target) => write!(f, "Creating {target} folder {folder}"),
Self::Cache(folder, target) => {
write!(f, "Adding {target} folder {folder} to cache")
}
Self::Delete(folder, target) => write!(f, "Deleting {target} folder {folder}"),
Self::Uncache(folder, target) => {
write!(f, "Removing {target} folder {folder} from cache")
}
}
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum FolderSyncCacheHunk {
Insert(FolderName, SyncDestination),
Delete(FolderName, SyncDestination),
}