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
//! Application-facing outcome type for batch Tree operations (`update_many`).
//! See `docs/superpowers/specs/26-06-24-armdb-batch-tree-ops.md`.
//!
//! The *control* type lives in [`crate::upsert`]: a batch closure returns the
//! same [`Upsert`](crate::Upsert) decision as a single-key `upsert`, so the
//! crate has one write-decision vocabulary rather than two.
/// Renamed to [`Upsert`](crate::Upsert) in 0.8.0, so one decision type covers
/// both `upsert` and `update_many`.
///
/// The `Set` variant is now `Put`; `Keep` and `Delete` are unchanged. The alias
/// keeps signatures naming the type compiling — call sites naming the variant
/// must be updated.
#[deprecated(
since = "0.8.0",
note = "renamed to `Upsert`; the `Set` variant is now `Put`"
)]
pub type BatchWrite<T> = crate::upsert::Upsert<T>;
/// What actually happened to one key — a self-sufficient application event
/// channel (`old` + `new` are present here, so duplicating an `on_write` hook is
/// optional).
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Applied<T> {
/// [`Upsert::Put`](crate::Upsert::Put) was applied. `old = Some(..)` on
/// overwrite, `None` on insert.
Written { old: Option<T>, new: T },
/// `Keep`, or `Delete` against an absent key.
Kept,
/// `Delete` against an existing key; carries the removed value.
Deleted(T),
}
#[cfg(test)]
mod tests {
use super::*;
use crate::Upsert;
#[test]
fn batch_types_construct_and_compare() {
let w: Upsert<u32> = Upsert::Put(7);
assert_eq!(w, Upsert::Put(7));
assert_ne!(w, Upsert::Keep);
let a: Applied<u32> = Applied::Written { old: None, new: 7 };
assert_eq!(a, Applied::Written { old: None, new: 7 });
assert_eq!(Applied::<u32>::Kept, Applied::Kept);
assert_eq!(Applied::Deleted(3u32), Applied::Deleted(3));
}
/// The deprecated alias still resolves to the same type.
#[test]
#[allow(deprecated)]
fn deprecated_alias_is_the_new_type() {
let w: BatchWrite<u32> = Upsert::Put(7);
assert_eq!(w, Upsert::Put(7));
}
}