I'm a rust newbie. This is not a homework question.
I know I can match on literals like the first match below. I've indicated where I need help below with vvvv. I'm checking if a
divides b
completely (if it does return a/b, else return err variant).
What pattern can I use in rust to match "not a literal"? Please suggest an idiomatic way to solve this. I was hoping to get the error variant first.
What I know:
- I can match with 0 and use
_
to match the error case.
pub fn divide(a: i32, b: i32) -> Result<i32, DivisionError> {
match b{
//return error variant if b is zero
0 => DivisionError::DivideByZero,
//if not error, then check if a divides b completely
_ => match a%b {
//vvvv This is where I need your help
!= 0 => 4,
}
}
}