salsa_macro_rules/
maybe_backdate.rs

1/// Conditionally update field value and backdate revisions
2#[macro_export]
3macro_rules! maybe_backdate {
4    (
5        ($return_mode:ident, no_backdate, $maybe_default:ident),
6        $maybe_update:tt,
7        $old_field_place:expr,
8        $new_field_place:expr,
9        $revision_place:expr,
10        $current_revision:expr,
11        $zalsa:ident,
12
13    ) => {
14        $zalsa::always_update(
15            &mut $revision_place,
16            $current_revision,
17            &mut $old_field_place,
18            $new_field_place,
19        );
20    };
21
22    (
23        ($return_mode:ident, backdate, $maybe_default:ident),
24        $maybe_update:tt,
25        $old_field_place:expr,
26        $new_field_place:expr,
27        $revision_place:expr,
28        $current_revision:expr,
29        $zalsa:ident,
30     ) => {
31        if $maybe_update(std::ptr::addr_of_mut!($old_field_place), $new_field_place) {
32            $revision_place = $current_revision;
33        }
34    };
35}