OptionExt

Trait OptionExt 

Source
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§

Source

fn ok_or_compile_error(self, kind: ErrorKind, span: Span) -> CompileResult<T>

Convert None to a CompileError with the given kind and span.

Implementations on Foreign Types§

Source§

impl<T> OptionExt<T> for Option<T>

Implementors§