pub trait RubyException {
// Required methods
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 raise
able 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§
Sourcefn message(&self) -> Cow<'_, [u8]>
fn message(&self) -> Cow<'_, [u8]>
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 String
s are best
represented as a Vec<u8>
.