summaryrefslogtreecommitdiffstats
path: root/src/process/process_result.rs
blob: acc4f032f8f571184ebaf7a80c4771b0285cfb46 (plain)
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
use crate::process::{ExitStatus, State};

#[derive(Debug)]
pub struct ProcessResult {
	pub exit_status: Option<ExitStatus>,
	pub state: Option<State>,
}

impl ProcessResult {
	pub fn new() -> Self {
		Self {
			exit_status: None,
			state: None,
		}
	}
}

pub struct ProcessResultBuilder {
	process_result: ProcessResult,
}

impl ProcessResultBuilder {
	pub fn new() -> Self {
		Self {
			process_result: ProcessResult {
				exit_status: None,
				state: None,
			},
		}
	}

	pub fn error(mut self, message: &str, return_state: State) -> Self {
		self.process_result.state = Some(State::Error {
			return_state: Box::new(return_state),
			message: String::from(message),
		});
		self
	}

	pub fn exit_status(mut self, status: ExitStatus) -> Self {
		self.process_result.exit_status = Some(status);
		self
	}

	pub fn state(mut self, new_state: State) -> Self {
		self.process_result.state = Some(new_state);
		self
	}

	pub fn build(self) -> ProcessResult {
		self.process_result
	}
}