I have a function that returns Result<Option<[type]>>
on an Input
type:
pub struct Input {
a: Option<i32>,
b: Option<i32>,
c: Option<i32>,
}
For each field in input
if the value is None
, the function will immediately return Ok(None)
and if there's a value, the function will unwrap it and proceed with further logic:
fn process(input: Input) -> std::io::Result<Option<i32>> {
let a = match input.a {
Some(a) => a,
None => return Ok(None),
};
// the same for b and c...
todo!()
}
The same pattern in repeated for all the fields in the input type. Is there a prettier way to express this?