Skip to main content

RError

Trait RError 

Source
pub trait RError {
    // Required methods
    fn error_message(&self) -> String;
    fn error_chain(&self) -> Vec<String>;
    fn error_chain_length(&self) -> i32;
}
Expand description

Adapter trait for std::error::Error.

Provides error message extraction and error chain walking for R. Automatically implemented for any type that implements Error.

§Methods

  • error_message() - Returns the error’s display message
  • error_chain() - Returns all messages in the error chain

§Example

use std::error::Error;
use std::fmt;

#[derive(Debug)]
struct MyError { msg: String, source: Option<Box<dyn Error + Send + Sync>> }

impl fmt::Display for MyError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{}", self.msg)
    }
}

impl Error for MyError {
    fn source(&self) -> Option<&(dyn Error + 'static)> {
        self.source.as_ref().map(|e| e.as_ref() as _)
    }
}

// Wrap in ExternalPtr for R access
#[derive(ExternalPtr)]
struct MyErrorWrapper(MyError);

#[miniextendr]
impl RError for MyErrorWrapper {}

Required Methods§

Source

fn error_message(&self) -> String

Get the error message (Display representation).

Source

fn error_chain(&self) -> Vec<String>

Get all error messages in the chain, from outermost to innermost.

Source

fn error_chain_length(&self) -> i32

Get the number of errors in the chain.

Implementors§

Source§

impl<T: Error> RError for T