qubit_argument/argument/mod.rs
1/*******************************************************************************
2 *
3 * Copyright (c) 2025 - 2026 Haixing Hu.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0.
8 *
9 ******************************************************************************/
10//! # Argument Validation
11//!
12//! Provides argument validation functionality similar to Java's `Argument` class, but with a design more suitable for Rust conventions.
13//!
14//! # Module Organization
15//!
16//! - `argument_error`: Error type definitions
17//! - `numeric_argument`: Numeric argument validation
18//! - `string_argument`: String argument validation
19//! - `collection_argument`: Collection argument validation
20//! - `option_argument`: Option argument validation
21//! - `condition`: Condition and state validation
22//!
23//! # Design Philosophy
24//!
25//! This module uses Rust's trait extension pattern to provide validation methods for various types.
26//! Compared to Java's static methods, this approach is more idiomatic in Rust and supports method chaining.
27//!
28//! # Usage Examples
29//!
30//! ```rust
31//! use qubit_argument::argument::{
32//! NumericArgument, StringArgument, CollectionArgument, ArgumentResult
33//! };
34//! use regex::Regex;
35//!
36//! fn process_user_input(
37//! age: i32,
38//! username: &str,
39//! tags: &[String],
40//! ) -> ArgumentResult<()> {
41//! // Numeric validation
42//! let age = age.require_in_closed_range("age", 0, 150)?;
43//!
44//! // String validation (regex + chaining)
45//! let username_pattern = Regex::new(r"^[a-zA-Z][a-zA-Z0-9_]{2,19}$").unwrap();
46//! let username = username
47//! .require_non_blank("username")?
48//! .require_match("username", &username_pattern)?;
49//!
50//! // Collection validation (chaining)
51//! let tags = tags
52//! .require_non_empty("tags")?
53//! .require_length_at_most("tags", 10)?;
54//!
55//! println!("Age: {}, Username: {}, Tag count: {}", age, username, tags.len());
56//! Ok(())
57//! }
58//! ```
59//!
60
61pub mod argument_error;
62pub mod collection_argument;
63pub mod condition;
64pub mod numeric_argument;
65pub mod option_argument;
66pub mod string_argument;
67
68// Re-export main types and traits
69pub use argument_error::{
70 ArgumentError,
71 ArgumentResult,
72};
73pub use collection_argument::{
74 CollectionArgument,
75 require_element_non_null,
76};
77pub use condition::{
78 check_argument,
79 check_argument_fmt,
80 check_argument_with_message,
81 check_bounds,
82 check_element_index,
83 check_position_index,
84 check_position_indexes,
85 check_state,
86 check_state_with_message,
87};
88pub use numeric_argument::{
89 NumericArgument,
90 require_equal,
91 require_not_equal,
92};
93pub use option_argument::{
94 OptionArgument,
95 require_null_or,
96};
97pub use string_argument::StringArgument;