1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
/*******************************************************************************
*
* Copyright (c) 2025 - 2026.
* Haixing Hu, Qubit Co. Ltd.
*
* All rights reserved.
*
******************************************************************************/
//! # Condition Argument Validation
//!
//! Provides general condition validation functionality.
//!
//! # Author
//!
//! Haixing Hu
use ;
/// Check if an argument condition is true
///
/// This is the most basic validation function for checking arbitrary boolean conditions.
///
/// # Parameters
///
/// * `condition` - The condition to check
///
/// # Returns
///
/// Returns `Ok(())` if the condition is true, otherwise returns an error
///
/// # Examples
///
/// ```rust,ignore
/// use qubit_common::lang::argument::check_argument;
///
/// let age = 25;
/// assert!(check_argument(age >= 18).is_ok());
/// assert!(check_argument(age < 18).is_err());
/// ```
///
/// # Author
///
/// Haixing Hu
///
/// Check if an argument condition is true and provide a custom error message
///
/// # Parameters
///
/// * `condition` - The condition to check
/// * `message` - Error message when condition is not satisfied
///
/// # Returns
///
/// Returns `Ok(())` if the condition is true, otherwise returns an error with custom message
///
/// # Examples
///
/// ```rust,ignore
/// use qubit_common::lang::argument::check_argument_with_message;
///
/// let count = 5;
/// let result = check_argument_with_message(
/// count > 0,
/// "Count must be positive"
/// );
/// assert!(result.is_ok());
/// ```
///
/// # Author
///
/// Haixing Hu
///
/// Check if an argument condition is true and use formatted message
///
/// # Parameters
///
/// * `condition` - The condition to check
/// * `format` - Format string
/// * `args` - Format arguments
///
/// # Returns
///
/// Returns `Ok(())` if the condition is true, otherwise returns formatted error message
///
/// # Examples
///
/// ```rust,ignore
/// use qubit_common::lang::argument::check_argument_fmt;
///
/// let value = 150;
/// let max = 100;
/// let result = check_argument_fmt(
/// value <= max,
/// format!("Value {} exceeds maximum {}", value, max)
/// );
/// assert!(result.is_err());
/// ```
///
/// # Author
///
/// Haixing Hu
///
/// Check if a state condition is true
///
/// Used to validate the state of an object or system. Similar to `check_argument` but semantically for state checking.
///
/// # Parameters
///
/// * `condition` - The state condition to check
///
/// # Returns
///
/// Returns `Ok(())` if the condition is true, otherwise returns an error
///
/// # Examples
///
/// ```rust,ignore
/// use qubit_common::lang::argument::check_state;
///
/// let is_initialized = true;
/// assert!(check_state(is_initialized).is_ok());
/// ```
///
/// # Author
///
/// Haixing Hu
///
/// Check if a state condition is true and provide a custom error message
///
/// # Parameters
///
/// * `condition` - The state condition to check
/// * `message` - Error message when condition is not satisfied
///
/// # Returns
///
/// Returns `Ok(())` if the condition is true, otherwise returns an error with custom message
///
/// # Examples
///
/// ```rust,ignore
/// use qubit_common::lang::argument::check_state_with_message;
///
/// let is_connected = false;
/// let result = check_state_with_message(
/// is_connected,
/// "Connection must be established first"
/// );
/// assert!(result.is_err());
/// ```
///
/// # Author
///
/// Haixing Hu
///
/// Check boundary conditions
///
/// Validates that offset and length are within valid range to prevent array bounds errors.
///
/// # Parameters
///
/// * `offset` - Starting offset
/// * `length` - Length to access
/// * `total_length` - Total length
///
/// # Returns
///
/// Returns `Ok(())` if boundaries are valid, otherwise returns an error
///
/// # Examples
///
/// ```rust,ignore
/// use qubit_common::lang::argument::check_bounds;
///
/// let buffer_len = 100;
/// assert!(check_bounds(10, 20, buffer_len).is_ok());
/// assert!(check_bounds(90, 20, buffer_len).is_err());
/// ```
///
/// # Author
///
/// Haixing Hu
///
/// Check if an index is within valid range
///
/// # Parameters
///
/// * `index` - The index to check
/// * `size` - Collection size
///
/// # Returns
///
/// Returns the index itself if valid, otherwise returns an error
///
/// # Examples
///
/// ```rust,ignore
/// use qubit_common::lang::argument::check_element_index;
///
/// let list_size = 10;
/// assert_eq!(check_element_index(5, list_size).unwrap(), 5);
/// assert!(check_element_index(10, list_size).is_err());
/// ```
///
/// # Author
///
/// Haixing Hu
///
/// Check if a position index is within valid range
///
/// Position index can equal size (for insertion operations).
///
/// # Parameters
///
/// * `index` - The position index to check
/// * `size` - Collection size
///
/// # Returns
///
/// Returns the index itself if valid, otherwise returns an error
///
/// # Examples
///
/// ```rust,ignore
/// use qubit_common::lang::argument::check_position_index;
///
/// let list_size = 10;
/// assert_eq!(check_position_index(10, list_size).unwrap(), 10); // Can equal size
/// assert!(check_position_index(11, list_size).is_err());
/// ```
///
/// # Author
///
/// Haixing Hu
///
/// Check if a position index range is valid
///
/// # Parameters
///
/// * `start` - Start index
/// * `end` - End index
/// * `size` - Collection size
///
/// # Returns
///
/// Returns `Ok(())` if the range is valid, otherwise returns an error
///
/// # Examples
///
/// ```rust,ignore
/// use qubit_common::lang::argument::check_position_indexes;
///
/// let list_size = 10;
/// assert!(check_position_indexes(2, 5, list_size).is_ok());
/// assert!(check_position_indexes(5, 2, list_size).is_err()); // start > end
/// ```
///
/// # Author
///
/// Haixing Hu
///