1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
use fmt;
pub use *;
pub use *;
/// Macro to enforce a condition and return an error if it fails.
///
/// # Example
/// ```rust
/// use b3_utils::require;
///
/// fn example_function(x: u32, y: u32) -> Result<(), String> {
/// require!(x < y, "x must be less than y");
/// Ok(())
/// }
///
/// assert_eq!(example_function(1, 2), Ok(()));
/// assert_eq!(example_function(2, 1), Err("x must be less than y".to_string()));
/// ```
/// Reports an error by converting it to a string.
///
/// # Example
/// ```
/// use b3_utils::report;
///
/// fn example_function() -> Result<(), String> {
/// if(true) {
/// return report("An error occurred");
/// }
///
/// Ok(())
/// }
///
/// assert_eq!(example_function(), Err("An error occurred".to_string()));
/// ```
/// Reports and logs an error (only when the "logging" feature is enabled).
///
/// # Example
/// ```
/// use b3_utils::{report_log, logs::export_log};
///
/// fn example_function() -> Result<(), String> {
/// if(true) {
/// return report_log("An error occurred");
/// }
///
/// Ok(())
/// }
///
/// assert_eq!(example_function(), Err("An error occurred".to_string()));
/// assert_eq!(export_log()[0].message, "An error occurred");
/// ```
/// Logs and panics with the given error message (only when the "logging" feature is enabled).
///
/// # Example
/// ```rust
/// use b3_utils::{panic_log, logs::export_log};
///
/// fn example_function() -> Result<(), String> {
/// if(true) {
/// return panic_log("An error occurred");
/// }
///
/// Ok(())
/// }
///
/// let result = std::panic::catch_unwind(|| example_function());
///
/// assert!(result.is_err());
///
/// assert_eq!(export_log()[0].message, "An error occurred");
/// ```