nu_engine::command_prelude

Trait ErrSpan

Source
pub trait ErrSpan {
    type Result;

    // Required method
    fn err_span(self, span: Span) -> Self::Result;
}
Expand description

An extension trait for Result, which adds a span to the error type.

Required Associated Types§

Required Methods§

Source

fn err_span(self, span: Span) -> Self::Result

Add the given span to the error type E, turning it into a Spanned<E>.

Some auto-conversion methods to ShellError from other error types are available on spanned errors, to give users better information about where an error came from. For example, it is preferred when working with std::io::Error:

use nu_protocol::{ErrSpan, ShellError, Span};
use std::io::Read;

fn read_from(mut reader: impl Read, span: Span) -> Result<Vec<u8>, ShellError> {
    let mut vec = vec![];
    reader.read_to_end(&mut vec).err_span(span)?;
    Ok(vec)
}

Implementations on Foreign Types§

Source§

impl<T, E> ErrSpan for Result<T, E>

Source§

type Result = Result<T, Spanned<E>>

Source§

fn err_span(self, span: Span) -> <Result<T, E> as ErrSpan>::Result

Implementors§