From 2588933ebc500f439ebef075fef1064b0c5f0bcb Mon Sep 17 00:00:00 2001 From: Weicao-CatilGrass <1992414357@qq.com> Date: Wed, 13 May 2026 07:34:45 +0800 Subject: Add convenient `update_exit_code` and `exit_code` helper functions --- mingling/src/res/exit_code.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'mingling/src/res') diff --git a/mingling/src/res/exit_code.rs b/mingling/src/res/exit_code.rs index 388a6f1..f4d4238 100644 --- a/mingling/src/res/exit_code.rs +++ b/mingling/src/res/exit_code.rs @@ -1,4 +1,28 @@ +use mingling_core::{ProgramCollect, this}; + +/// Represents a program exit code. #[derive(Debug, Default, Clone, Copy)] pub struct ExitCode { + /// The numeric exit code value. pub exit_code: i32, } + +/// Updates the globally stored exit code for the given `ProgramCollect` type. +pub fn update_exit_code(exit_code: i32) +where + C: ProgramCollect + 'static, +{ + this::().modify_res(|e: &mut ExitCode| e.exit_code = exit_code); +} + +/// Retrieves the globally stored exit code for the given `ProgramCollect` type. +/// Returns `0` if no exit code has been set. +pub fn exit_code() -> i32 +where + C: ProgramCollect + 'static, +{ + match this::().res::() { + Some(e) => e.exit_code, + None => 0, + } +} -- cgit