macro_rules! required_field {
($field:expr, $error:expr) => { ... };
}Expand description
Extracts and validates a required Option<T> field.
This macro simplifies the common pattern of extracting a required field from an Option,
returning an error if the field is None.
§Arguments
$field- TheOption<T>field to extract$error- The error to return if the field isNone
§Examples
ⓘ
fn extract_fields(self) -> Result<(u32, String)> {
let id = required_field!(self.id, Error::message(Error::MESSAGE_ID_REQUIRED))?;
let name = required_field!(self.name, Error::message(Error::MESSAGE_NAME_EMPTY))?;
Ok((id, name))
}