aboutsummaryrefslogtreecommitdiff
path: root/mingling_core/src/renderer/render_result.rs
diff options
context:
space:
mode:
Diffstat (limited to 'mingling_core/src/renderer/render_result.rs')
-rw-r--r--mingling_core/src/renderer/render_result.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/mingling_core/src/renderer/render_result.rs b/mingling_core/src/renderer/render_result.rs
index 8757376..fc3f2b1 100644
--- a/mingling_core/src/renderer/render_result.rs
+++ b/mingling_core/src/renderer/render_result.rs
@@ -1,6 +1,7 @@
use std::{
fmt::{Display, Formatter},
io::Write,
+ process::{ExitCode, exit},
};
use crate::RenderResultMode::{Stderr, Stdout};
@@ -99,6 +100,18 @@ macro_rules! impl_from_int {
impl_from_int!(i32, i16, i8, u32, u16, u8, usize);
+impl From<RenderResult> for ExitCode {
+ fn from(value: RenderResult) -> Self {
+ ExitCode::from(value.exit_code as u8)
+ }
+}
+
+impl From<&RenderResult> for ExitCode {
+ fn from(value: &RenderResult) -> Self {
+ ExitCode::from(value.exit_code as u8)
+ }
+}
+
impl From<&String> for RenderResult {
fn from(value: &String) -> Self {
string_to_render_result(value, Stdout)
@@ -483,6 +496,24 @@ impl RenderResult {
exit_code: self.exit_code,
}
}
+
+ /// Exits the process with the exit code stored in this `RenderResult`.
+ ///
+ /// This method calls `std::process::exit()` with the `exit_code` value,
+ /// terminating the current process immediately.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use mingling_core::RenderResult;
+ ///
+ /// let mut result = RenderResult::new();
+ /// result.exit_code = 42;
+ /// // result.exit_process(); // would exit with code 42
+ /// ```
+ pub fn exit_process(&self) {
+ exit(self.exit_code)
+ }
}
#[inline(always)]