I'd like to iterate over a list of Option
s. If there's a value in one of them, I want to return an error. Here's a contrived example:
fn test(options: &[Option<u8>]) -> Result<(), &u8> {
for option in options {
match option {
None => (),
Some(value) => {
// do some stuff here, so I can't just go
// Some(value) => return Err(value),
return Err(value); // this semicolon is optional
}
}
}
Ok(())
}
Adding another semicolon results in an error, but deleting the semicolon does not.
Why is the semicolon after the return statement optional?
Which form should be used in idiomatic Rust: semicolon or no semicolon? Both are accepted by the compiler and seem to produce the same result.