pub fn flag_error<T, E>(flag: &mut bool, result: Result<T, E>) -> Result<T, E>Expand description
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 theOkvariant of theResult.E: The type contained in theErrvariant of theResult.
§Arguments
flag: A mutable reference to a boolean flag that will be set totrueif theResultcontains an error.result: TheResultto check for an error.
§Returns
- Returns the provided
Resultvalue for further use or propagation.
§Examples
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.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.