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
//! # Macros
//!
//! `cirious_codex_result` provides several macros for easily creating `CodexOk` and `CodexError` instances.
/// Macro for quickly wrapping a value and optional metadata into an `Ok(CodexOk)`.
///
/// # Examples
///
/// ```
/// use cirious_codex_result::{codex_ok, Result};
///
/// fn process() -> Result<&'static str> {
/// // Returns immediately with metadata
/// codex_ok!("Done", "time_ms" => "12", "id" => "99")
/// }
/// ```
/// Macro for immediate exit from a function with a `CodexError`.
///
/// Use this macro to propagate an error when a failure condition is met.
/// It automatically injects the caller's location and accepts optional
/// metadata for extended diagnostics.
///
/// # Examples
///
/// ```
/// use cirious_codex_result::{codex_bail, codex_ok, Result};
///
/// fn find_user(id: u32) -> Result<String> {
/// if id == 0 {
/// codex_bail!("INVALID_ID", "User ID cannot be zero", "attempted" => "0");
/// }
/// codex_ok!("User".to_string().into())
/// }
/// ```
/// Macro for validating a condition and returning a `CodexError` if it fails.
///
/// Acts as an assertion that, when false, exits the function with an error
/// document containing the provided context and metadata.
///
/// # Examples
///
/// ```
/// use cirious_codex_result::{codex_ensure, codex_ok, Result};
///
/// fn login(token: &str) -> Result<()> {
/// codex_ensure!(!token.is_empty(), "AUTH_FAILED", "Token is missing");
/// codex_ok!(())
/// }
/// ```