ixc_core/
lib.rs

1#![doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/README.md"))]
2#![no_std]
3
4#[cfg(feature = "std")]
5extern crate alloc;
6
7mod context;
8mod events;
9pub mod message;
10pub mod account_api;
11pub mod handler;
12pub mod resource;
13pub mod error;
14pub mod routing;
15pub mod low_level;
16pub mod result;
17
18pub use context::Context;
19pub use events::EventBus;
20pub use handler::Service;
21pub use account_api::create_account;
22
23pub use result::{Result};
24
25/// Create an error.
26#[macro_export]
27macro_rules! error {
28    ($code:path) => {
29        $crate::error::HandlerError::new_from_code($code)
30    };
31    ($code:path, $str:literal, $($arg:tt)*) => {
32        $crate::error::HandlerError::new_fmt_with_code($code, core::format_args!($str, $($arg)*))
33    };
34    ($str:literal) => {
35        $crate::error::HandlerError::new($str.to_string())
36    };
37    ($str:literal, $($arg:tt)*) => {
38        $crate::error::HandlerError::new_fmt(core::format_args!($str, $($arg)*))
39    };
40}
41
42/// Return an error with a formatted message.
43#[macro_export]
44macro_rules! bail {
45    ($($arg:tt)*) => {
46        return core::result::Result::Err($crate::error!($($arg)*));
47    };
48}
49
50/// Ensure a condition is true, otherwise return an error with a formatted message.
51#[macro_export]
52macro_rules! ensure {
53    ($cond:expr, $($arg:tt)*) => {
54        if !$cond {
55            return core::result::Result::Err($crate::error!($($arg)*));
56        }
57    };
58}