thruput_sdk/storage/deletable.rs
1/// Trait for storage types whose data can be fully deleted.
2///
3/// Leaf types (NNInt, Value, Bytestring) delete their single storage key.
4/// Compound types implement this recursively when their elements are
5/// Deletable. Types like Map that cannot enumerate entries do not
6/// implement this trait.
7pub trait Deletable {
8 /// Delete storage for this node.
9 ///
10 /// `exclusive` is the deletion's write policy. Leaf implementors combine
11 /// it with their keypath's own exclusivity and, if either is set, request
12 /// an exclusive lock once the deletion succeeds; compound implementors
13 /// pass it to each child. This makes exclusivity additive: calling
14 /// `delete()` on a slot accessed via `at_mut_exclusive()` still locks the
15 /// deletion.
16 fn delete_internal(&mut self, exclusive: bool);
17
18 /// Delete using the keypath's own locking semantics.
19 fn delete(&mut self) {
20 self.delete_internal(false);
21 }
22
23 /// Delete, then request an exclusive lock, regardless of keypath flag.
24 /// Later writes in the transaction keep the lock.
25 fn delete_exclusive(&mut self) {
26 self.delete_internal(true);
27 }
28}