pub struct FlagCounter { /* private fields */ }
Expand description
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).
Implementations§
Source§impl FlagCounter
impl FlagCounter
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates and returns a new instance of the struct with the count
field initialized to 0.
§Returns
A new instance of the struct.
Sourcepub fn check<T, E>(&mut self, result: Result<T, E>) -> Result<T, E>
pub fn check<T, E>(&mut self, result: Result<T, E>) -> Result<T, E>
Checks the provided Result
, increments an internal error count if it is Err
, and returns the Result
unchanged.
§Type Parameters
T
: The type of the value inside theOk
variant of theResult
.E
: The type of the error inside theErr
variant of theResult
.
§Arguments
result
: AResult
value to be checked for an error.
§Behavior
- If the provided
Result
isErr
, the method increments the internal error count (self.count
). - Regardless of whether it is
Ok
orErr
, the originalResult
is returned unchanged.
§Returns
Returns the provided Result
value as-is.
Sourcepub fn is_flagged(&self) -> bool
pub fn is_flagged(&self) -> bool
Checks if the current object is flagged.
§Returns
true
- If thecount
property of the object is greater than 0.false
- If thecount
property of the object is 0 or less.
§Usage
This function acts as a flagging mechanism. For example, it can be used to determine if there are any active or positive counts that signify certain conditions.
§Note
The count
field must be initialized appropriately before calling this function.