Is there a more compact way to write this?

51 points No-Face8472

I've got a function that contains a guard statement that looks something like this:

match some_enum_value {
  A(value) => {
    if value == 5 {
      return Err(CustomError::IncorrectValue);
    }

    Ok(())
  },
  _ => Err(CustomError::InvalidEnumValue),
}?;

I want it to check if a variable (some\_enum\_value) is a certain kind. If it is not, I want to return an error. If it is the correct kind I want to check the kind's inner value and conditionally return a different error or an Ok if the condition is not met. Is there a better, perhaps more compact way to write this?