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
//! This module contains a function for flagging an error in a `Result` type.
//!
//! # Use Case
//! - Propagating errors in a `Result` type.
//! - Tracking whether an error occurred in a `Result` type.
/// Flags an error while propagating the result of a `Result` type.
///
/// This function takes a mutable boolean reference (`flag`) and a `Result` value.
/// If the `Result` is an error (`Err`), it sets the `flag` to `true`, allowing the
/// caller to track if an error occurred without consuming the `Result`.
///
/// The original `Result` is then returned unchanged.
///
/// # Type Parameters
/// - `T`: The type contained in the `Ok` variant of the `Result`.
/// - `E`: The type contained in the `Err` variant of the `Result`.
///
/// # Arguments
/// - `flag`: A mutable reference to a boolean flag that will be set to `true`
/// if the `Result` contains an error.
/// - `result`: The `Result` to check for an error.
///
/// # Returns
/// - Returns the provided `Result` value for further use or propagation.
///
/// # Examples
/// ```rust
/// use cjtoolkit_structured_validator::common::flag_error::flag_error;
/// let mut error_occurred = false;
/// let result: Result<i32, &str> = Err("An error occurred");
///
/// let checked_result = flag_error(&mut error_occurred, result);
///
/// assert!(error_occurred); // Flag has been set to true.
/// assert!(checked_result.is_err()); // The result is returned unchanged.
/// ```
///
/// ```rust
/// use cjtoolkit_structured_validator::common::flag_error::flag_error;
/// let mut error_occurred = false;
/// let result: Result<i32, &str> = Ok(42);
///
/// let checked_result = flag_error(&mut error_occurred, result);
///
/// assert!(!error_occurred); // Flag remains false.
/// assert_eq!(checked_result, Ok(42)); // The result is returned unchanged.
/// ```
/// A structure that provides a counter for managing flags or similar use cases.
///
/// The `FlagCounter` struct is designed to keep track of an incrementable count,
/// typically to represent or manage a counter for specific operations or states.
///
/// # Fields
///
/// * `count`:
/// - The current value of the counter.
/// - Represented as a `usize` (unsigned integer).