pub trait OptionExt<T> {
// Required method
fn ok_or_compile_error(
self,
kind: ErrorKind,
span: Span,
) -> CompileResult<T>;
}Expand description
Extension trait for converting Option<T> to CompileResult<T>.
This trait simplifies the common pattern of converting lookup failures
(returning None) into compilation errors with source spans.
§Example
ⓘ
use gruel_error::{OptionExt, ErrorKind};
let result = ctx.locals.get(name)
.ok_or_compile_error(ErrorKind::UndefinedVariable(name_str.to_string()), span)?;Required Methods§
Sourcefn ok_or_compile_error(self, kind: ErrorKind, span: Span) -> CompileResult<T>
fn ok_or_compile_error(self, kind: ErrorKind, span: Span) -> CompileResult<T>
Convert None to a CompileError with the given kind and span.