WrapToExecutionResult

Trait WrapToExecutionResult 

Source
pub trait WrapToExecutionResult<R, RE, W>: Sized {
    // Required method
    fn wrap_to_execution_result(self, result: &W) -> ExecutionResult<R, RE>;
}
Expand description

Convert Result<T,TE> to ExecutionResult<R,E>, taking context from ExecutionResponse.

Required Methods§

Source

fn wrap_to_execution_result(self, result: &W) -> ExecutionResult<R, RE>

Convert self (eg. some Result) to ExecutionResult, taking context information from W (eg. ExecutionResponse).

This function simplifies processing of results by wrapping them into ExecutionResult. It is useful when you have execution result retrieved in previous step and you want to add it to the result of the current step.

Useful when chaining multiple commands and you want to keep track of retries and address.

§Example
use rs_dapi_client::{ExecutionResponse, ExecutionResult, WrapToExecutionResult};

fn some_request() -> ExecutionResult<i8, String> {
    Ok(ExecutionResponse {
        inner: 42,
        retries: 123,
        address: "http://127.0.0.1".parse().expect("create mock address"),
    })
}

fn next_step() -> Result<i32, String> {
    Err("next error".to_string())
}

let response = some_request().expect("request should succeed");
let result: ExecutionResult<i32, String> = next_step().wrap_to_execution_result(&response);

if let ExecutionResult::Err(error) = result {
   assert_eq!(error.inner, "next error");
   assert_eq!(error.retries, 123);
} else {
   panic!("Expected error");
}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<R, RE, TR, IR, IRE> WrapToExecutionResult<R, RE, ExecutionResponse<TR>> for Result<IR, IRE>
where R: From<IR>, RE: From<IRE>,

Implementors§