aboutsummaryrefslogtreecommitdiff
path: root/mingling_core/src
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-07-18 05:35:51 +0800
committer魏曹先生 <1992414357@qq.com>2026-07-18 05:35:51 +0800
commit250f578e6b876d19d3f136fa0ebf91672e0a1b01 (patch)
tree76905aa011c33ddd928403cab61b10269d64aba1 /mingling_core/src
parente89608805efe7a24ab72b8030bc307b6a4f6d6fc (diff)
feat(program): add mutable access, take, and replace for program args
Diffstat (limited to 'mingling_core/src')
-rw-r--r--mingling_core/src/program.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/mingling_core/src/program.rs b/mingling_core/src/program.rs
index 71d5290..0d409b7 100644
--- a/mingling_core/src/program.rs
+++ b/mingling_core/src/program.rs
@@ -130,6 +130,33 @@ where
&self.args
}
+ /// Returns a mutable reference to the program's command-line arguments.
+ #[must_use]
+ pub fn get_args_mut(&mut self) -> &mut [String] {
+ &mut self.args
+ }
+
+ /// Takes ownership of the program's command-line arguments, replacing them with an empty Vec.
+ /// This is useful when you need to transfer the arguments to another context or process them
+ /// and then replace them later.
+ #[must_use]
+ pub fn take_args(&mut self) -> Vec<String> {
+ std::mem::take(&mut self.args)
+ }
+
+ /// Replaces the program's command-line arguments with a new set and returns the old ones.
+ ///
+ /// # Arguments
+ ///
+ /// * `args` - The new command-line arguments to set.
+ ///
+ /// # Returns
+ ///
+ /// The previous command-line arguments.
+ pub fn replace_args(&mut self, args: Vec<String>) -> Vec<String> {
+ std::mem::replace(&mut self.args, args)
+ }
+
/// Get all registered dispatcher names from the program
#[must_use]
pub fn get_nodes(