miden_lib/errors/
masm_error.rs1use alloc::borrow::Cow;
2
3use miden_objects::Felt;
4
5pub struct MasmError {
7 message: Cow<'static, str>,
8}
9
10impl MasmError {
11 pub const fn from_static_str(message: &'static str) -> Self {
13 Self { message: Cow::Borrowed(message) }
14 }
15
16 pub fn new(message: impl Into<Cow<'static, str>>) -> Self {
18 let message = message.into();
19
20 Self { message }
21 }
22
23 pub fn message(&self) -> &str {
25 &self.message
26 }
27
28 pub fn code(&self) -> Felt {
30 miden_objects::assembly::mast::error_code_from_msg(&self.message)
31 }
32}
33
34impl core::fmt::Display for MasmError {
35 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
36 f.write_fmt(format_args!("\"{}\" (code: {})", self.message(), self.code()))
37 }
38}