Metadata

Struct Metadata 

Source
pub struct Metadata {
    pub app_name: &'static str,
    pub app_description: &'static str,
    pub help_flag_name: Option<&'static str>,
    pub help_mode: bool,
    pub full_help: bool,
    pub is_valid_flag_chars: fn(&str) -> bool,
}
Expand description

Metadata of RawArgs.

Fields§

§app_name: &'static str

Application name (e.g., env!("CARGO_PKG_NAME")).

§app_description: &'static str

Application description (e.g., env!("CARGO_PKG_DESCRIPTION")).

§help_flag_name: Option<&'static str>

Flag name for help (default: Some("help")).

§help_mode: bool

When enabled, the following help mode behaviors apply:

§full_help: bool

If true, a full help text will be displayed.

§is_valid_flag_chars: fn(&str) -> bool

Predicate function to determine if a string contains only valid flag characters.

This function is used when parsing short flags to distinguish between:

  • Multiple flags (e.g., -abc where each character is a flag)
  • Options with concatenated values (e.g., -khello where ‘k’ is an option and “hello” is its value)

The default implementation accepts only ASCII alphabetic characters, which prevents ambiguity in parsing. For example, with -khello world, the presence of space and non-alphabetic characters indicates this is an option with a concatenated value rather than multiple flags.

§Example: Only accept flags actually defined by the app

use noargs::{raw_args, flag};

let mut args = raw_args();

// Define the valid short flags for your app
const VALID_FLAGS: &[char] = &['h', 'v', 'q', 'd'];

// Only allow characters that correspond to actual flags in your app
args.metadata_mut().is_valid_flag_chars = |chars| {
    chars.chars().all(|c| VALID_FLAGS.contains(&c))
};

// Now only -h, -v, -q, -d and their combinations (like -hv, -vd) are valid
// Anything else like -khello be treated as an option with concatenated value
let help_flag = flag("help").short('h').take(&mut args);
let verbose_flag = flag("verbose").short('v').take(&mut args);
let quiet_flag = flag("quiet").short('q').take(&mut args);
let debug_flag = flag("debug").short('d').take(&mut args);

Trait Implementations§

Source§

impl Clone for Metadata

Source§

fn clone(&self) -> Metadata

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Metadata

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Metadata

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Hash for Metadata

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Metadata

Source§

fn eq(&self, other: &Metadata) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Metadata

Source§

impl Eq for Metadata

Source§

impl StructuralPartialEq for Metadata

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.