Trait spinoso_exception::RubyException[][src]

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

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

fn message(&self) -> Cow<'_, [u8]>[src]

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>.

fn name(&self) -> Cow<'_, str>[src]

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>.

Loading content...

Implementors

impl RubyException for ArgumentError[src]

impl RubyException for EOFError[src]

impl RubyException for EncodingError[src]

impl RubyException for Exception[src]

impl RubyException for Fatal[src]

impl RubyException for FiberError[src]

impl RubyException for FloatDomainError[src]

impl RubyException for FrozenError[src]

impl RubyException for IOError[src]

impl RubyException for IndexError[src]

impl RubyException for Interrupt[src]

impl RubyException for KeyError[src]

impl RubyException for LoadError[src]

impl RubyException for LocalJumpError[src]

impl RubyException for NameError[src]

impl RubyException for NoMemoryError[src]

impl RubyException for NoMethodError[src]

impl RubyException for NotImplementedError[src]

impl RubyException for RangeError[src]

impl RubyException for RegexpError[src]

impl RubyException for RuntimeError[src]

impl RubyException for ScriptError[src]

impl RubyException for SecurityError[src]

impl RubyException for SignalException[src]

impl RubyException for StandardError[src]

impl RubyException for StopIteration[src]

impl RubyException for SyntaxError[src]

impl RubyException for SystemCallError[src]

impl RubyException for SystemExit[src]

impl RubyException for SystemStackError[src]

impl RubyException for ThreadError[src]

impl RubyException for TypeError[src]

impl RubyException for UncaughtThrowError[src]

impl RubyException for ZeroDivisionError[src]

Loading content...