match_result_code_optional

Function match_result_code_optional 

Source
pub fn match_result_code_optional<F, T>(
    result_code: i32,
    on_success: F,
) -> Result<Option<T>>
where F: FnOnce() -> Option<T>,
Expand description

Evaluates a result code and executes a closure on success, handling optional return values.

This function is similar to match_result_code but is designed to work with closures that return Option<T> values, making it suitable for operations that may legitimately return no data even on success.

§Arguments

  • result_code - An integer representing the operation result code
  • on_success - A closure that will be executed if result_code >= 0, returning Option<T>

§Type Parameters

  • F - The type of the closure that returns Option<T>
  • T - The inner type of the optional value returned by the closure

§Returns

Returns a Result<Option<T>> where:

  • Ok(Some(T)) - Contains the value returned by the closure if result_code >= 0 and closure returns Some
  • Ok(None) - If result_code >= 0 but the closure returns None
  • Err(Error) - For negative result codes

§Note

This function treats all non-negative result codes as success, allowing the closure to determine whether data is present through its Option return type.