pub type CommonResult<T> = Result<T, Box<dyn Error + Send + Sync>>;
Expand description

Type alias to make it easy to work with Results. Works hand in hand w/ CommonError. Here’s an example.

pub fn try_from_pair(pair: Pair) -> CommonResult<(Percent, Percent)> {
  let first = pair.first.try_into();
  let second = pair.second.try_into();

  match (first, second) {
    (Ok(first), Ok(second)) => Ok((first, second)),
    _ => {
      let err_msg = format!("Invalid percentage values in tuple: {:?}", pair);
      CommonError::new(CommonErrorType::ValueOutOfRange, &err_msg)
    }
  }
}

Aliased Type§

enum CommonResult<T> {
    Ok(T),
    Err(Box<dyn Error + Send + Sync>),
}

Variants§

§1.0.0

Ok(T)

Contains the success value

§1.0.0

Err(Box<dyn Error + Send + Sync>)

Contains the error value