fastsim_core/
macros.rs

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
#[macro_export]
macro_rules! check_orphaned_and_set {
    ($struct_self: ident, $field: ident, $value: expr) => {
        // TODO: This seems like it could be used instead, but raises an error
        // ensure!(!$struct_self.orphaned, utils::NESTED_STRUCT_ERR);
        // $struct_self.$field = $value;
        // Ok(())

        if !$struct_self.orphaned {
            $struct_self.$field = $value;
            anyhow::Ok(())
        } else {
            bail!(utils::NESTED_STRUCT_ERR)
        }
    };
}

#[macro_export]
/// Generates a String similar to output of `dbg` but without printing
macro_rules! format_dbg {
    ($dbg_expr:expr) => {
        format!(
            "[{}:{}] {}: {:?}",
            file!(),
            line!(),
            stringify!($dbg_expr),
            $dbg_expr
        )
    };
    () => {
        format!("[{}:{}]", file!(), line!())
    };
}