templar_vault_kernel/
abort.rs1pub const OVERFLOW: &str = "arithmetic under/overflow";
2
3#[inline]
4pub fn abort_unreachable() -> ! {
5 #[cfg(target_arch = "wasm32")]
6 {
7 core::arch::wasm32::unreachable()
8 }
9
10 #[cfg(not(target_arch = "wasm32"))]
11 {
12 panic!("abort_unreachable invoked")
13 }
14}
15
16#[inline]
17pub fn unwrap_abort_option<T>(value: Option<T>, _msg: &'static str) -> T {
18 match value {
19 Some(value) => value,
20 None => abort_unreachable(),
21 }
22}
23
24#[inline]
25pub fn unwrap_abort_result<T, E>(value: Result<T, E>, _msg: &'static str) -> T {
26 match value {
27 Ok(value) => value,
28 Err(_) => abort_unreachable(),
29 }
30}
31
32#[macro_export]
33macro_rules! abort {
34 ($msg:expr $(,)?) => {{
35 #[cfg(not(target_arch = "wasm32"))]
36 {
37 panic!($msg)
38 }
39
40 #[cfg(target_arch = "wasm32")]
41 {
42 let _ = $msg;
43 $crate::abort::abort_unreachable()
44 }
45 }};
46}
47
48#[macro_export]
49macro_rules! unwrap_abort {
50 ($value:expr, $msg:expr $(,)?) => {{
51 $crate::abort::unwrap_abort_option($value, $msg)
52 }};
53}
54
55#[macro_export]
56macro_rules! unwrap_abort_result {
57 ($value:expr, $msg:expr $(,)?) => {{
58 $crate::abort::unwrap_abort_result($value, $msg)
59 }};
60}