Trait spinoso_exception::RubyException[][src]

pub trait RubyException {
    fn message(&self) -> Cow<'_, [u8]>;
fn name(&self) -> Cow<'_, str>; }
Expand description

Polymorphic exception type that corresponds to Ruby’s Exception.

This trait unifies all concrete exception types defined in this crate and is object safe. This means RubyException can be used as a trait object to represent an error type of any set of exception subclasses.

All types that implement RubyException should be raiseable in an Artichoke Ruby VM.

Examples

fn array_concat(slf: Array, other: Array) -> Result<Array, Box<dyn RubyException>> {
    if slf.is_frozen() {
        return Err(Box::new(FrozenError::new()));
    }
    Err(Box::new(NotImplementedError::new()))
}

Required methods

The exception’s message.

Examples

fn exception_inspect(exc: &dyn RubyException) {
    let message = exc.message();
    let message = String::from_utf8_lossy(&message);
    println!("{} ({})", exc.name(), message);
}

Implementation notes

This method returns a byte slice since Ruby Strings are best represented as a Vec<u8>.

The exception’s class name.

Examples

fn exception_inspect(exc: &dyn RubyException) {
    let message = exc.message();
    let message = String::from_utf8_lossy(&message);
    println!("{} ({})", exc.name(), message);
}

Implementation notes

This method returns a byte slice since Ruby Strings are best represented as a Vec<u8>.

Implementors