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;

    // Provided methods
#[doc(hidden)]
unsafe extern "C" fn __RError_error_message_shim( data: *mut c_void, argc: i32, argv: *const SEXP, ) -> SEXP where Self: Sized + RError { ... }
#[doc(hidden)]
unsafe extern "C" fn __RError_error_chain_shim( data: *mut c_void, argc: i32, argv: *const SEXP, ) -> SEXP where Self: Sized + RError { ... }
#[doc(hidden)]
unsafe extern "C" fn __RError_error_chain_length_shim( data: *mut c_void, argc: i32, argv: *const SEXP, ) -> SEXP where Self: Sized + RError { ... } }
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 miniextendr_api::adapter_traits::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.

Provided Methods§

Source

#[doc(hidden)]
unsafe extern "C" fn __RError_error_message_shim( data: *mut c_void, argc: i32, argv: *const SEXP, ) -> SEXP
where Self: Sized + RError,

Method shim for RError::error_message.

Converts SEXP arguments, calls the method, and returns SEXP result. Both Rust panics and R longjmps are caught via with_r_unwind_protect.

Source

#[doc(hidden)]
unsafe extern "C" fn __RError_error_chain_shim( data: *mut c_void, argc: i32, argv: *const SEXP, ) -> SEXP
where Self: Sized + RError,

Method shim for RError::error_chain.

Converts SEXP arguments, calls the method, and returns SEXP result. Both Rust panics and R longjmps are caught via with_r_unwind_protect.

Source

#[doc(hidden)]
unsafe extern "C" fn __RError_error_chain_length_shim( data: *mut c_void, argc: i32, argv: *const SEXP, ) -> SEXP
where Self: Sized + RError,

Method shim for RError::error_chain_length.

Converts SEXP arguments, calls the method, and returns SEXP result. Both Rust panics and R longjmps are caught via with_r_unwind_protect.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T: Error> RError for T