use alloc::borrow::Cow;
use crate::Felt;
pub struct MasmError {
message: Cow<'static, str>,
}
impl MasmError {
pub const fn from_static_str(message: &'static str) -> Self {
Self { message: Cow::Borrowed(message) }
}
pub fn new(message: impl Into<Cow<'static, str>>) -> Self {
let message = message.into();
Self { message }
}
pub fn message(&self) -> &str {
&self.message
}
pub fn code(&self) -> Felt {
crate::assembly::mast::error_code_from_msg(&self.message)
}
}
impl core::fmt::Display for MasmError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_fmt(format_args!("\"{}\" (code: {})", self.message(), self.code()))
}
}