aboutsummaryrefslogtreecommitdiff
path: root/mingling_core/src/program/flag.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-04-01 20:14:56 +0800
committer魏曹先生 <1992414357@qq.com>2026-04-01 20:16:17 +0800
commitf1ed18e668a830646fe507ee33c4b010a1690342 (patch)
tree6d13b5ca65ec4df6b8df1c03df3c96301d435bbf /mingling_core/src/program/flag.rs
parent227e710fe716c8901ee02e670a57fb70eb3f222b (diff)
Add documentation for mingling_core
Diffstat (limited to 'mingling_core/src/program/flag.rs')
-rw-r--r--mingling_core/src/program/flag.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/mingling_core/src/program/flag.rs b/mingling_core/src/program/flag.rs
index 84fae01..a520495 100644
--- a/mingling_core/src/program/flag.rs
+++ b/mingling_core/src/program/flag.rs
@@ -2,6 +2,45 @@ use std::fmt::Display;
use crate::{Program, ProgramCollect};
+/// A wrapper for a collection of static string slices representing command-line flags or arguments.
+///
+/// `Flag` is used to store one or more static string slices (e.g., `["-h", "--help"]`) that
+/// represent command-line flags or arguments. It provides conversions from various input types
+/// (like a single `&'static str`, a slice, or an array) and dereferences to a slice of strings
+/// for easy iteration and access.
+///
+/// # Examples
+///
+/// ```
+/// use mingling_core::Flag;
+///
+/// // Create a Flag from a single string slice
+/// let flag1 = Flag::from("-h");
+/// assert_eq!(flag1.as_ref(), &["-h"]);
+///
+/// // Create a Flag from a slice of string slices
+/// let flag2 = Flag::from(&["-h", "--help"][..]);
+/// assert_eq!(flag2.as_ref(), &["-h", "--help"]);
+///
+/// // Create a Flag from an array
+/// let flag3 = Flag::from(["-v", "--verbose"]);
+/// assert_eq!(flag3.as_ref(), &["-v", "--verbose"]);
+///
+/// // Create a Flag from a reference to an array
+/// let arr = &["-f", "--file"];
+/// let flag4 = Flag::from(arr);
+/// assert_eq!(flag4.as_ref(), &["-f", "--file"]);
+///
+/// // Create an empty Flag from unit type
+/// let flag5 = Flag::from(());
+/// assert_eq!(flag5.as_ref(), &[] as &[&str]);
+///
+/// // Dereference to slice for iteration
+/// let flag = Flag::from(["-a", "-b"]);
+/// for arg in flag.iter() {
+/// println!("Flag: {}", arg);
+/// }
+/// ```
pub struct Flag {
vec: Vec<&'static str>,
}
@@ -57,6 +96,7 @@ impl std::ops::Deref for Flag {
}
#[macro_export]
+#[doc(hidden)]
macro_rules! special_flag {
($args:expr, $flag:expr) => {{
let flag = $flag;
@@ -67,6 +107,7 @@ macro_rules! special_flag {
}
#[macro_export]
+#[doc(hidden)]
macro_rules! special_argument {
($args:expr, $flag:expr) => {{
let flag = $flag;