artichoke_backend/extn/core/math/
mod.rsuse std::borrow::Cow;
use crate::extn::prelude::*;
pub(in crate::extn) mod mruby;
pub(super) mod trampoline;
#[doc(inline)]
pub use spinoso_math::{DomainError, Math, E, PI};
use spinoso_math::{Error as MathError, NotImplementedError as MathNotImplementedError};
impl RubyException for DomainError {
fn message(&self) -> Cow<'_, [u8]> {
let message = DomainError::message(*self);
Cow::Borrowed(message.as_bytes())
}
fn name(&self) -> Cow<'_, str> {
"DomainError".into()
}
fn vm_backtrace(&self, interp: &mut Artichoke) -> Option<Vec<Vec<u8>>> {
let _ = interp;
None
}
fn as_mrb_value(&self, interp: &mut Artichoke) -> Option<sys::mrb_value> {
let message = interp.try_convert_mut(self.message()).ok()?;
let value = interp.new_instance::<Self>(&[message]).ok().flatten()?;
Some(value.inner())
}
}
impl From<DomainError> for Error {
fn from(exception: DomainError) -> Self {
let err: Box<dyn RubyException> = Box::new(exception);
Self::from(err)
}
}
impl From<MathNotImplementedError> for Error {
fn from(err: MathNotImplementedError) -> Self {
let exc = NotImplementedError::from(err.message());
exc.into()
}
}
impl From<MathError> for Error {
fn from(err: MathError) -> Self {
match err {
MathError::Domain(err) => err.into(),
MathError::NotImplemented(err) => err.into(),
}
}
}