email/folder/sync/
hunk.rs1use std::fmt;
7
8use super::*;
9use crate::sync::SyncDestination;
10
11pub type FolderName = String;
13
14pub type FoldersName = HashSet<FolderName>;
16
17#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
19pub enum FolderSyncHunk {
20 Create(FolderName, SyncDestination),
23
24 Cache(FolderName, SyncDestination),
27
28 Delete(FolderName, SyncDestination),
31
32 Uncache(FolderName, SyncDestination),
35}
36
37impl FolderSyncHunk {
38 pub fn is_left(&self) -> bool {
39 match self {
40 Self::Create(_, SyncDestination::Left) => true,
41 Self::Cache(_, SyncDestination::Left) => true,
42 Self::Delete(_, SyncDestination::Left) => true,
43 Self::Uncache(_, SyncDestination::Left) => true,
44 _ => false,
45 }
46 }
47
48 pub fn is_right(&self) -> bool {
49 match self {
50 Self::Create(_, SyncDestination::Right) => true,
51 Self::Cache(_, SyncDestination::Right) => true,
52 Self::Delete(_, SyncDestination::Right) => true,
53 Self::Uncache(_, SyncDestination::Right) => true,
54 _ => false,
55 }
56 }
57
58 pub fn folder(&self) -> &str {
59 match self {
60 Self::Create(folder, _) => folder.as_str(),
61 Self::Cache(folder, _) => folder.as_str(),
62 Self::Delete(folder, _) => folder.as_str(),
63 Self::Uncache(folder, _) => folder.as_str(),
64 }
65 }
66}
67
68impl fmt::Display for FolderSyncHunk {
69 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
70 match self {
71 Self::Create(folder, target) => write!(f, "Creating {target} folder {folder}"),
72 Self::Cache(folder, target) => {
73 write!(f, "Adding {target} folder {folder} to cache")
74 }
75 Self::Delete(folder, target) => write!(f, "Deleting {target} folder {folder}"),
76 Self::Uncache(folder, target) => {
77 write!(f, "Removing {target} folder {folder} from cache")
78 }
79 }
80 }
81}
82
83#[derive(Clone, Debug, Eq, PartialEq)]
88pub enum FolderSyncCacheHunk {
89 Insert(FolderName, SyncDestination),
92
93 Delete(FolderName, SyncDestination),
96}