aboutsummaryrefslogtreecommitdiff
path: root/mingling_core/src
diff options
context:
space:
mode:
Diffstat (limited to 'mingling_core/src')
-rw-r--r--mingling_core/src/program.rs27
-rw-r--r--mingling_core/src/program/setup.rs17
2 files changed, 44 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(
diff --git a/mingling_core/src/program/setup.rs b/mingling_core/src/program/setup.rs
index f248fb6..838c29a 100644
--- a/mingling_core/src/program/setup.rs
+++ b/mingling_core/src/program/setup.rs
@@ -1,9 +1,26 @@
use crate::{ProgramCollect, program::Program};
+/// Trait for defining initialization/setup logic for a `Program`.
+///
+/// Implementors can define custom setup behavior that will be executed
+/// when the program is initialized via [`Program::with_setup`].
+///
+/// # Type Parameters
+///
+/// * `C` - The program collect type, which must implement [`ProgramCollect`]
+/// and have `Enum = C` (i.e., it collects itself).
pub trait ProgramSetup<C>
where
C: ProgramCollect<Enum = C>,
{
+ /// Perform setup on the given program.
+ ///
+ /// This method consumes the setup instance (`self`) and is called once
+ /// during program initialization.
+ ///
+ /// # Arguments
+ ///
+ /// * `program` - A mutable reference to the [`Program`] being set up.
fn setup(self, program: &mut Program<C>);
}