pg_embed_alternative/
pg_enums.rs1use std::error::Error;
6
7use crate::command_executor::ProcessStatus;
8use crate::pg_errors::{PgEmbedError, PgEmbedErrorType};
9
10pub enum PgAuthMethod {
17 Plain,
19 MD5,
21 ScramSha256,
23}
24
25#[derive(Debug, Clone, Copy, PartialEq)]
29pub enum PgServerStatus {
30 Uninitialized,
32 Initializing,
34 Initialized,
36 Starting,
38 Started,
40 Stopping,
42 Stopped,
44 Failure,
46}
47
48pub enum PgProcessType {
54 InitDb,
56 StartDb,
58 StopDb,
60}
61
62impl ProcessStatus<PgServerStatus, PgEmbedError> for PgProcessType {
63 fn status_entry(&self) -> PgServerStatus {
64 match self {
65 PgProcessType::InitDb => PgServerStatus::Initializing,
66 PgProcessType::StartDb => PgServerStatus::Starting,
67 PgProcessType::StopDb => PgServerStatus::Stopping,
68 }
69 }
70
71 fn status_exit(&self) -> PgServerStatus {
72 match self {
73 PgProcessType::InitDb => PgServerStatus::Initialized,
74 PgProcessType::StartDb => PgServerStatus::Started,
75 PgProcessType::StopDb => PgServerStatus::Stopped,
76 }
77 }
78
79 fn error_type(&self) -> PgEmbedError {
80 match self {
81 PgProcessType::InitDb => PgEmbedError {
82 error_type: PgEmbedErrorType::PgInitFailure,
83 source: None,
84 message: None,
85 },
86 PgProcessType::StartDb => PgEmbedError {
87 error_type: PgEmbedErrorType::PgStartFailure,
88 source: None,
89 message: None,
90 },
91 PgProcessType::StopDb => PgEmbedError {
92 error_type: PgEmbedErrorType::PgStopFailure,
93 source: None,
94 message: None,
95 },
96 }
97 }
98
99 fn wrap_error<E: Error + Sync + Send + 'static>(
100 &self,
101 error: E,
102 message: Option<String>,
103 ) -> PgEmbedError {
104 PgEmbedError {
105 error_type: PgEmbedErrorType::PgError,
106 source: Some(Box::new(error)),
107 message,
108 }
109 }
110}
111
112impl ToString for PgProcessType {
113 fn to_string(&self) -> String {
114 match self {
115 PgProcessType::InitDb => "initdb".to_string(),
116 PgProcessType::StartDb => "start".to_string(),
117 PgProcessType::StopDb => "stop".to_string(),
118 }
119 }
120}
121
122#[derive(Debug, PartialEq, Copy, Clone)]
124pub enum OperationSystem {
125 Darwin,
126 Windows,
127 Linux,
128 AlpineLinux,
129}
130
131impl ToString for OperationSystem {
132 fn to_string(&self) -> String {
133 match &self {
134 OperationSystem::Darwin => "darwin".to_string(),
135 OperationSystem::Windows => "windows".to_string(),
136 OperationSystem::Linux => "linux".to_string(),
137 OperationSystem::AlpineLinux => "linux".to_string(),
138 }
139 }
140}
141
142impl Default for OperationSystem {
143 fn default() -> Self {
144 #[cfg(not(any(target_os = "linux", target_os = "windows")))]
145 {
146 OperationSystem::Darwin
147 }
148
149 #[cfg(target_os = "linux")]
150 {
151 OperationSystem::Linux
152 }
153
154 #[cfg(target_os = "windows")]
155 {
156 OperationSystem::Windows
157 }
158 }
159}
160
161#[derive(Debug, PartialEq, Copy, Clone)]
163pub enum Architecture {
164 Amd64,
165 I386,
166 Arm32v6,
167 Arm32v7,
168 Arm64v8,
169 Ppc64le,
170}
171
172impl ToString for Architecture {
173 fn to_string(&self) -> String {
174 match &self {
175 Architecture::Amd64 => "amd64".to_string(),
176 Architecture::I386 => "i386".to_string(),
177 Architecture::Arm32v6 => "arm32v6".to_string(),
178 Architecture::Arm32v7 => "arm32v7".to_string(),
179 Architecture::Arm64v8 => "arm64v8".to_string(),
180 Architecture::Ppc64le => "ppc64le".to_string(),
181 }
182 }
183}
184
185impl Default for Architecture {
186 fn default() -> Self {
187 #[cfg(not(any(
188 target_arch = "x86",
189 target_arch = "arm",
190 target_arch = "aarch64",
191 target_arch = "powerpc64"
192 )))]
193 {
194 Architecture::Amd64
195 }
196
197 #[cfg(target_arch = "x86")]
198 {
199 Architecture::I386
200 }
201
202 #[cfg(target_arch = "arm")]
203 {
204 Architecture::Arm32v7
205 }
206
207 #[cfg(target_arch = "aarch64")]
208 {
209 Architecture::Arm64v8
210 }
211
212 #[cfg(target_arch = "powerpc64")]
213 {
214 Architecture::Ppc64le
215 }
216 }
217}
218
219#[derive(Copy, Clone, PartialEq)]
221pub enum PgAcquisitionStatus {
222 InProgress,
224 Finished,
226 Undefined,
228}