expect_field

Macro expect_field 

Source
macro_rules! expect_field {
    ($($body:tt)+) => { ... };
}
Expand description

Converts an Option to a Result, using the extracted field name for error context.

This macro extracts field names from expressions and uses them to create descriptive NotFound errors when the Option is None. It works with variable names, struct fields, method calls, and complex expressions.

§Example

use bigerror::{expect_field, NotFound, Report};

struct User {
    email: Option<String>,
}

let user = User { email: None };
let result: Result<&String, Report<NotFound>> = expect_field!(user.email.as_ref());
// Error will show: field "email" is missing
assert!(result.is_err());