1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//! Support for Palm HotSync, with pluggable sync conduits

use core::{
	cmp::PartialEq,
	default::Default,
	fmt::{self, Debug, Display},
	str::FromStr,
};

pub mod conduit;

/// Sync mode
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum SyncMode {
	/// Prefer the data from local storage
	KeepLocal,

	/// Prefer the data from the remote Palm OS device
	KeepDevice,

	/// Perform a merge of the local and remote datasets
	Merge,
}

impl Default for SyncMode {
	fn default() -> Self {
		Self::Merge
	}
}

impl FromStr for SyncMode {
	type Err = String;

	fn from_str(s: &str) -> Result<Self, Self::Err> {
		match s.to_ascii_lowercase().as_str() {
			"keep-local" | "keeplocal" | "local" => Ok(Self::KeepLocal),
			"keep-device" | "keepdevice" | "device" => Ok(Self::KeepDevice),
			"merge" => Ok(Self::Merge),

			_ => Err(String::from(s)),
		}
	}
}

impl Display for SyncMode {
	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
		match self {
			Self::KeepLocal => write!(f, "keep-local"),
			Self::KeepDevice => write!(f, "keep-device"),
			Self::Merge => write!(f, "merge"),
		}
	}
}