1use std::fmt;
6
7use crate::command_executor::ProcessStatus;
8use crate::pg_errors::Error;
9
10pub enum PgAuthMethod {
17 Plain,
19 MD5,
21 ScramSha256,
23}
24
25impl fmt::Display for PgAuthMethod {
26 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27 match self {
28 PgAuthMethod::Plain => write!(f, "password"),
29 PgAuthMethod::MD5 => write!(f, "md5"),
30 PgAuthMethod::ScramSha256 => write!(f, "scram-sha-256"),
31 }
32 }
33}
34
35#[derive(Debug, Clone, Copy, PartialEq)]
39pub enum PgServerStatus {
40 Uninitialized,
42 Initializing,
44 Initialized,
46 Starting,
48 Started,
50 Stopping,
52 Stopped,
54 Failure,
56}
57
58pub enum PgProcessType {
64 InitDb,
66 StartDb,
68 StopDb,
70}
71
72impl ProcessStatus<PgServerStatus, Error> for PgProcessType {
73 fn status_entry(&self) -> PgServerStatus {
74 match self {
75 PgProcessType::InitDb => PgServerStatus::Initializing,
76 PgProcessType::StartDb => PgServerStatus::Starting,
77 PgProcessType::StopDb => PgServerStatus::Stopping,
78 }
79 }
80
81 fn status_exit(&self) -> PgServerStatus {
82 match self {
83 PgProcessType::InitDb => PgServerStatus::Initialized,
84 PgProcessType::StartDb => PgServerStatus::Started,
85 PgProcessType::StopDb => PgServerStatus::Stopped,
86 }
87 }
88
89 fn error_type(&self) -> Error {
90 match self {
91 PgProcessType::InitDb => Error::PgInitFailure,
92 PgProcessType::StartDb => Error::PgStartFailure,
93 PgProcessType::StopDb => Error::PgStopFailure,
94 }
95 }
96
97 fn timeout_error(&self) -> Error {
98 Error::PgTimedOutError
99 }
100
101 fn wrap_error<E: std::error::Error + Sync + Send + 'static>(
102 &self,
103 error: E,
104 message: Option<String>,
105 ) -> Error {
106 Error::PgError(error.to_string(), message.unwrap_or_default())
107 }
108}
109
110impl fmt::Display for PgProcessType {
111 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
112 match self {
113 PgProcessType::InitDb => write!(f, "initdb"),
114 PgProcessType::StartDb => write!(f, "start"),
115 PgProcessType::StopDb => write!(f, "stop"),
116 }
117 }
118}
119
120#[derive(Debug, PartialEq, Copy, Clone)]
122pub enum OperationSystem {
123 Darwin,
125 Windows,
127 Linux,
129 AlpineLinux,
131}
132
133impl fmt::Display for OperationSystem {
134 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
135 match self {
136 OperationSystem::Darwin => write!(f, "darwin"),
137 OperationSystem::Windows => write!(f, "windows"),
138 OperationSystem::Linux => write!(f, "linux"),
139 OperationSystem::AlpineLinux => write!(f, "linux"),
140 }
141 }
142}
143
144#[allow(clippy::derivable_impls)]
145impl Default for OperationSystem {
146 fn default() -> Self {
147 #[cfg(not(any(target_os = "linux", target_os = "windows")))]
148 {
149 OperationSystem::Darwin
150 }
151
152 #[cfg(target_os = "linux")]
153 {
154 OperationSystem::Linux
155 }
156
157 #[cfg(target_os = "windows")]
158 {
159 OperationSystem::Windows
160 }
161 }
162}
163
164#[derive(Debug, PartialEq, Copy, Clone)]
166pub enum Architecture {
167 Amd64,
169 I386,
171 Arm32v6,
173 Arm32v7,
175 Arm64v8,
177 Ppc64le,
179}
180
181impl fmt::Display for Architecture {
182 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
183 match self {
184 Architecture::Amd64 => write!(f, "amd64"),
185 Architecture::I386 => write!(f, "i386"),
186 Architecture::Arm32v6 => write!(f, "arm32v6"),
187 Architecture::Arm32v7 => write!(f, "arm32v7"),
188 Architecture::Arm64v8 => write!(f, "arm64v8"),
189 Architecture::Ppc64le => write!(f, "ppc64le"),
190 }
191 }
192}
193
194#[allow(clippy::derivable_impls)]
195impl Default for Architecture {
196 fn default() -> Self {
197 #[cfg(not(any(
198 target_arch = "x86",
199 target_arch = "arm",
200 target_arch = "aarch64",
201 target_arch = "powerpc64"
202 )))]
203 {
204 Architecture::Amd64
205 }
206
207 #[cfg(target_arch = "x86")]
208 {
209 Architecture::I386
210 }
211
212 #[cfg(target_arch = "arm")]
213 {
214 Architecture::Arm32v7
215 }
216
217 #[cfg(target_arch = "aarch64")]
218 {
219 Architecture::Arm64v8
220 }
221
222 #[cfg(target_arch = "powerpc64")]
223 {
224 Architecture::Ppc64le
225 }
226 }
227}
228
229#[derive(Copy, Clone, PartialEq)]
231pub enum PgAcquisitionStatus {
232 InProgress,
234 Finished,
236 Undefined,
238}
239
240#[cfg(test)]
241mod tests {
242 use super::*;
243
244 #[test]
245 fn test_operation_system_display() {
246 assert_eq!(OperationSystem::Darwin.to_string(), "darwin");
247 assert_eq!(OperationSystem::Windows.to_string(), "windows");
248 assert_eq!(OperationSystem::Linux.to_string(), "linux");
249 assert_eq!(OperationSystem::AlpineLinux.to_string(), "linux");
250 }
251
252 #[test]
253 fn test_architecture_display() {
254 assert_eq!(Architecture::Amd64.to_string(), "amd64");
255 assert_eq!(Architecture::I386.to_string(), "i386");
256 assert_eq!(Architecture::Arm32v6.to_string(), "arm32v6");
257 assert_eq!(Architecture::Arm32v7.to_string(), "arm32v7");
258 assert_eq!(Architecture::Arm64v8.to_string(), "arm64v8");
259 assert_eq!(Architecture::Ppc64le.to_string(), "ppc64le");
260 }
261}