escrow_machines 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,453 @@
1
+ #![cfg_attr(not(test), no_std)]
2
+ #![cfg_attr(not(test), deny(clippy::indexing_slicing))]
3
+ //! Bounded-counter escrow: a fixed set of replicas shares a fixed supply of
4
+ //! rights, and each replica may spend only the rights it holds locally.
5
+ //!
6
+ //! The state is the bounded-counter CRDT of Balegas et al.: a matrix of
7
+ //! cumulative grants between replicas plus per-replica spent and refunded
8
+ //! counters, all grow-only and joined cell by cell. Unlike an unrestricted
9
+ //! PN-counter, a spend is checked against the local share before it is
10
+ //! recorded, so the sum of everything spent can never exceed the supply, no
11
+ //! matter how the replicas are partitioned. Unlike a rate limiter, nothing
12
+ //! refills: rights move, they are never minted.
13
+ //!
14
+ //! Each replica writes only its own cells: its spent and refunded counters and
15
+ //! its row of outgoing grants. Everything else it learns through
16
+ //! [`Escrow::merge`] or [`Escrow::accept`]. That ownership is the whole safety
17
+ //! argument, and it makes two things the caller's contract:
18
+ //!
19
+ //! * **Durable replica identities.** A replica must persist its state (see
20
+ //! [`Escrow::encode`]) before acting on a successful spend, refund or
21
+ //! transfer. A replica that restarts from an older state under the same
22
+ //! identity can spend the same rights twice. [`Escrow::merge`] refuses with
23
+ //! [`Refusal::Diverged`] when a peer proves that happened.
24
+ //! * **Transfer replay protection.** A transfer carries a caller-chosen id that
25
+ //! strictly increases per `(from, to)` pair. Retrying the latest id returns
26
+ //! the original [`Receipt`]; an older id is refused. Receipts are cumulative,
27
+ //! so delivering one twice, late, or out of order is harmless.
28
+ //!
29
+ //! Nothing here reads a clock, talks to a network, stores anything, or
30
+ //! allocates.
31
+
32
+ mod frame;
33
+ mod merge;
34
+ mod ops;
35
+ mod table;
36
+ #[cfg(test)]
37
+ mod tests;
38
+
39
+ pub use merge_machines::{Merge, ReplicaId};
40
+ use table::{Member, Tally};
41
+
42
+ /// The latest transfer one replica made to another. Built only through
43
+ /// [`Mark::new`], so it never records a transfer of nothing.
44
+ #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
45
+ pub struct Mark {
46
+ id: u64,
47
+ amount: u64,
48
+ }
49
+
50
+ impl Mark {
51
+ /// The mark of transfer `id` moving `amount`, or `None` for an amount of
52
+ /// zero: no transfer moves nothing.
53
+ #[must_use]
54
+ pub const fn new(id: u64, amount: u64) -> Option<Self> {
55
+ if amount == 0 {
56
+ return None;
57
+ }
58
+ Some(Self { id, amount })
59
+ }
60
+
61
+ /// The caller-chosen id of that transfer.
62
+ #[must_use]
63
+ pub const fn id(&self) -> u64 {
64
+ self.id
65
+ }
66
+
67
+ /// How many rights it moved.
68
+ #[must_use]
69
+ pub const fn amount(&self) -> u64 {
70
+ self.amount
71
+ }
72
+ }
73
+
74
+ /// Proof of one transfer, safe to deliver any number of times in any order.
75
+ /// Built only by [`Escrow::transfer`] or [`Receipt::new`], so it never
76
+ /// contradicts itself.
77
+ #[derive(Debug, Clone, Copy, PartialEq, Eq)]
78
+ pub struct Receipt {
79
+ from: ReplicaId,
80
+ to: ReplicaId,
81
+ id: u64,
82
+ amount: u64,
83
+ total: u64,
84
+ }
85
+
86
+ impl Receipt {
87
+ /// A receipt that does not contradict itself, or `None` when it names one
88
+ /// replica on both ends, moves nothing, or moves more than the cumulative
89
+ /// `total` it claims.
90
+ #[must_use]
91
+ pub const fn new(
92
+ from: ReplicaId,
93
+ to: ReplicaId,
94
+ id: u64,
95
+ amount: u64,
96
+ total: u64,
97
+ ) -> Option<Self> {
98
+ if from == to || amount == 0 || amount > total {
99
+ return None;
100
+ }
101
+ Some(Self {
102
+ from,
103
+ to,
104
+ id,
105
+ amount,
106
+ total,
107
+ })
108
+ }
109
+
110
+ /// The replica that gave the rights away.
111
+ #[must_use]
112
+ pub const fn from(&self) -> ReplicaId {
113
+ self.from
114
+ }
115
+
116
+ /// The replica that received them.
117
+ #[must_use]
118
+ pub const fn to(&self) -> ReplicaId {
119
+ self.to
120
+ }
121
+
122
+ /// The caller-chosen id of the transfer.
123
+ #[must_use]
124
+ pub const fn id(&self) -> u64 {
125
+ self.id
126
+ }
127
+
128
+ /// How many rights this transfer moved.
129
+ #[must_use]
130
+ pub const fn amount(&self) -> u64 {
131
+ self.amount
132
+ }
133
+
134
+ /// Everything `from` has ever granted `to`, this transfer included.
135
+ #[must_use]
136
+ pub const fn total(&self) -> u64 {
137
+ self.total
138
+ }
139
+ }
140
+
141
+ /// What a transfer request did.
142
+ #[derive(Debug, Clone, Copy, PartialEq, Eq)]
143
+ pub enum Transfer {
144
+ /// The rights moved now.
145
+ Applied(Receipt),
146
+ /// This id already moved these rights; nothing moved again.
147
+ Replayed(Receipt),
148
+ }
149
+
150
+ impl Transfer {
151
+ /// The receipt to deliver, the same one whether applied or replayed.
152
+ #[must_use]
153
+ pub const fn receipt(&self) -> Receipt {
154
+ match self {
155
+ Self::Applied(receipt) | Self::Replayed(receipt) => *receipt,
156
+ }
157
+ }
158
+ }
159
+
160
+ /// What a delivered receipt did.
161
+ #[derive(Debug, Clone, Copy, PartialEq, Eq)]
162
+ pub enum Accepted {
163
+ /// The receipt taught this replica about a grant it had not seen.
164
+ Applied,
165
+ /// This replica already knew everything the receipt says.
166
+ Replayed,
167
+ }
168
+
169
+ /// Why a call changed nothing.
170
+ #[derive(Debug, Clone, Copy, PartialEq, Eq)]
171
+ pub enum Refusal {
172
+ /// The amount was zero.
173
+ ZeroAmount,
174
+ /// The local replica holds fewer rights than the call needs.
175
+ Insufficient {
176
+ /// The rights the local replica holds.
177
+ available: u64,
178
+ },
179
+ /// A refund asked for more than the local replica has outstanding.
180
+ ExceedsSpent {
181
+ /// Local spends not yet refunded.
182
+ outstanding: u64,
183
+ },
184
+ /// A replica id is outside the configured set.
185
+ UnknownReplica,
186
+ /// A transfer named the same replica on both ends.
187
+ SelfTransfer,
188
+ /// The transfer id is older than the latest one for this pair.
189
+ StaleId {
190
+ /// The latest id recorded for the pair.
191
+ latest: u64,
192
+ },
193
+ /// The id was already used for this pair with a different amount.
194
+ IdConflict {
195
+ /// The amount recorded under that id.
196
+ amount: u64,
197
+ },
198
+ /// A receipt contradicts itself or the history it claims to extend, or
199
+ /// a frame describes a state no sequence of calls produces.
200
+ Malformed,
201
+ /// A receipt claims a grant from the local replica that it never made.
202
+ Forged,
203
+ /// The other state was built for a different replica set or allotment.
204
+ ConfigMismatch,
205
+ /// The other state knows more about the local replica's own cells than the
206
+ /// local replica does, or two histories disagree about one transfer.
207
+ Diverged,
208
+ /// Adopting the other state would leave the local replica below zero.
209
+ Overdrawn,
210
+ /// A cumulative counter or the local balance would pass [`u64::MAX`].
211
+ Overflow,
212
+ /// The buffer is shorter than the frame.
213
+ Truncated,
214
+ /// The frame does not lead with the escrow tag.
215
+ WrongStructure,
216
+ /// The frame was written for another capacity `N`.
217
+ WrongShape,
218
+ }
219
+
220
+ impl core::fmt::Display for Refusal {
221
+ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
222
+ match self {
223
+ Self::ZeroAmount => f.write_str("the amount is zero"),
224
+ Self::Insufficient { available } => {
225
+ write!(f, "the local replica holds only {available}")
226
+ }
227
+ Self::ExceedsSpent { outstanding } => {
228
+ write!(f, "only {outstanding} is spent and not refunded")
229
+ }
230
+ Self::UnknownReplica => f.write_str("the replica is outside the configured set"),
231
+ Self::SelfTransfer => f.write_str("the transfer names one replica on both ends"),
232
+ Self::StaleId { latest } => {
233
+ write!(f, "the latest transfer id for the pair is {latest}")
234
+ }
235
+ Self::IdConflict { amount } => write!(f, "the id already moved {amount}"),
236
+ Self::Malformed => f.write_str("the receipt or frame describes what no calls produce"),
237
+ Self::Forged => f.write_str("the receipt claims a grant the local replica never made"),
238
+ Self::ConfigMismatch => f.write_str("the other state has another allotment"),
239
+ Self::Diverged => {
240
+ f.write_str("the other state knows more of the local replica's cells")
241
+ }
242
+ Self::Overdrawn => {
243
+ f.write_str("the adopted history leaves the local replica below zero")
244
+ }
245
+ Self::Overflow => f.write_str("a counter or the balance would pass u64::MAX"),
246
+ Self::Truncated => f.write_str("buffer too short"),
247
+ Self::WrongStructure => f.write_str("not an escrow frame"),
248
+ Self::WrongShape => f.write_str("the frame was written for another capacity"),
249
+ }
250
+ }
251
+ }
252
+
253
+ impl core::error::Error for Refusal {}
254
+
255
+ /// Why an escrow could not be built.
256
+ #[derive(Debug, Clone, Copy, PartialEq, Eq)]
257
+ pub enum ConfigError {
258
+ /// The allotment names no replica.
259
+ NoReplicas,
260
+ /// The allotment names more replicas than the capacity `N`.
261
+ TooManyReplicas,
262
+ /// The local replica is not in the allotment.
263
+ UnknownReplica,
264
+ /// The allotment adds up to more than [`u64::MAX`].
265
+ SupplyOverflow,
266
+ }
267
+
268
+ /// One replica's view of a supply of rights shared by up to `N` replicas.
269
+ ///
270
+ /// ```
271
+ /// use escrow_machines::{Escrow, Refusal};
272
+ ///
273
+ /// let mut left = Escrow::<4>::new(0, &[10, 0]).unwrap();
274
+ /// let mut right = Escrow::<4>::new(1, &[10, 0]).unwrap();
275
+ ///
276
+ /// assert_eq!(right.spend(1), Err(Refusal::Insufficient { available: 0 }));
277
+ ///
278
+ /// let moved = left.transfer(1, 1, 4).unwrap();
279
+ /// assert_eq!(left.available(), 6);
280
+ /// right.accept(&moved.receipt()).unwrap();
281
+ /// assert_eq!(right.spend(4), Ok(0));
282
+ ///
283
+ /// // A retry of the same id moves nothing more.
284
+ /// assert_eq!(left.transfer(1, 1, 4).unwrap().receipt(), moved.receipt());
285
+ /// assert_eq!(left.available(), 6);
286
+ /// ```
287
+ #[derive(Debug, Clone, Copy, PartialEq, Eq)]
288
+ pub struct Escrow<const N: usize> {
289
+ local: Member<N>,
290
+ replicas: usize,
291
+ allotted: [u64; N],
292
+ spent: Tally<N>,
293
+ refunded: Tally<N>,
294
+ /// `grants[from]` counts, per receiving replica, what `from` gave away.
295
+ grants: [Tally<N>; N],
296
+ /// `marks[from][to]` is the latest transfer `from` made to `to`.
297
+ marks: [[Option<Mark>; N]; N],
298
+ }
299
+
300
+ impl<const N: usize> Escrow<N> {
301
+ /// How many replicas this shape can hold.
302
+ pub const CAPACITY: usize = N;
303
+
304
+ /// The view of replica `local`, where replica `i` starts with
305
+ /// `allotted[i]` rights. Every replica must be built from the same
306
+ /// allotment.
307
+ ///
308
+ /// # Errors
309
+ ///
310
+ /// [`ConfigError`] when the allotment is empty, longer than `N`, does not
311
+ /// include `local`, or adds up to more than [`u64::MAX`].
312
+ pub fn new(local: ReplicaId, allotted: &[u64]) -> Result<Self, ConfigError> {
313
+ if allotted.is_empty() {
314
+ return Err(ConfigError::NoReplicas);
315
+ }
316
+ if allotted.len() > N {
317
+ return Err(ConfigError::TooManyReplicas);
318
+ }
319
+ let local = usize::try_from(local)
320
+ .ok()
321
+ .filter(|index| *index < allotted.len())
322
+ .and_then(Member::new)
323
+ .ok_or(ConfigError::UnknownReplica)?;
324
+ allotted
325
+ .iter()
326
+ .try_fold(0_u64, |sum, share| sum.checked_add(*share))
327
+ .ok_or(ConfigError::SupplyOverflow)?;
328
+ let mut shares = [0; N];
329
+ for (slot, share) in shares.iter_mut().zip(allotted) {
330
+ *slot = *share;
331
+ }
332
+ Ok(Self {
333
+ local,
334
+ replicas: allotted.len(),
335
+ allotted: shares,
336
+ spent: Tally::new(),
337
+ refunded: Tally::new(),
338
+ grants: [Tally::new(); N],
339
+ marks: [[None; N]; N],
340
+ })
341
+ }
342
+
343
+ /// The replica this view belongs to.
344
+ #[must_use]
345
+ pub const fn local(&self) -> ReplicaId {
346
+ self.local.id()
347
+ }
348
+
349
+ /// How many replicas share the supply.
350
+ #[must_use]
351
+ pub const fn replicas(&self) -> usize {
352
+ self.replicas
353
+ }
354
+
355
+ /// Every right that exists, held or spent.
356
+ #[must_use]
357
+ pub fn supply(&self) -> u64 {
358
+ self.allotted
359
+ .iter()
360
+ .fold(0_u64, |sum, share| sum.saturating_add(*share))
361
+ }
362
+
363
+ /// The rights `replica` started with.
364
+ #[must_use]
365
+ pub fn allotted(&self, replica: ReplicaId) -> Option<u64> {
366
+ self.index(replica).map(|member| *member.of(&self.allotted))
367
+ }
368
+
369
+ /// The rights the local replica holds and may spend or transfer now.
370
+ #[must_use]
371
+ pub fn available(&self) -> u64 {
372
+ u64::try_from(self.signed_balance(self.local)).unwrap_or(0)
373
+ }
374
+
375
+ /// The rights `replica` holds as far as this view knows. For another
376
+ /// replica this is an estimate, and it is negative when this view has seen
377
+ /// that replica pass on rights whose arrival it has not seen yet.
378
+ #[must_use]
379
+ pub fn balance(&self, replica: ReplicaId) -> Option<i128> {
380
+ self.index(replica)
381
+ .map(|member| self.signed_balance(member))
382
+ }
383
+
384
+ /// Everything `replica` has spent, as far as this view knows.
385
+ #[must_use]
386
+ pub fn spent(&self, replica: ReplicaId) -> Option<u64> {
387
+ self.index(replica).map(|member| self.spent.count(member))
388
+ }
389
+
390
+ /// Everything `replica` has refunded, as far as this view knows.
391
+ #[must_use]
392
+ pub fn refunded(&self, replica: ReplicaId) -> Option<u64> {
393
+ self.index(replica)
394
+ .map(|member| self.refunded.count(member))
395
+ }
396
+
397
+ /// What `replica` has spent and not refunded, as far as this view knows.
398
+ #[must_use]
399
+ pub fn outstanding(&self, replica: ReplicaId) -> Option<u64> {
400
+ self.index(replica)
401
+ .map(|member| self.outstanding_of(member))
402
+ }
403
+
404
+ /// Everything `from` has granted `to`, as far as this view knows.
405
+ #[must_use]
406
+ pub fn granted(&self, from: ReplicaId, to: ReplicaId) -> Option<u64> {
407
+ let (from, to) = (self.index(from)?, self.index(to)?);
408
+ Some(from.of(&self.grants).count(to))
409
+ }
410
+
411
+ /// The latest transfer `from` made to `to`, as far as this view knows.
412
+ #[must_use]
413
+ pub fn last_transfer(&self, from: ReplicaId, to: ReplicaId) -> Option<Mark> {
414
+ let (from, to) = (self.index(from)?, self.index(to)?);
415
+ *to.of(from.of(&self.marks))
416
+ }
417
+
418
+ /// Where `replica` sits in the tables, if it is one of the replicas.
419
+ fn index(&self, replica: ReplicaId) -> Option<Member<N>> {
420
+ usize::try_from(replica)
421
+ .ok()
422
+ .filter(|index| *index < self.replicas)
423
+ .and_then(Member::new)
424
+ }
425
+
426
+ /// What `member` has spent and not refunded.
427
+ const fn outstanding_of(&self, member: Member<N>) -> u64 {
428
+ self.spent
429
+ .count(member)
430
+ .saturating_sub(self.refunded.count(member))
431
+ }
432
+
433
+ /// Allotment plus every grant `member` received, as far as this view
434
+ /// knows. At most `N + 1` terms of at most `u64::MAX`, far inside `i128`.
435
+ fn inflow(&self, member: Member<N>) -> i128 {
436
+ let received: i128 = self
437
+ .grants
438
+ .iter()
439
+ .map(|row| i128::from(row.count(member)))
440
+ .sum();
441
+ i128::from(*member.of(&self.allotted)) + received
442
+ }
443
+
444
+ /// Allotment plus grants received, minus grants made and net spends.
445
+ ///
446
+ /// No overflow: each term is at most `u64::MAX` and there are fewer than
447
+ /// `2 * N + 3` of them, far inside `i128`.
448
+ fn signed_balance(&self, member: Member<N>) -> i128 {
449
+ let given = member.of(&self.grants).total();
450
+ self.inflow(member) - given - i128::from(self.spent.count(member))
451
+ + i128::from(self.refunded.count(member))
452
+ }
453
+ }
@@ -0,0 +1,132 @@
1
+ //! Joining two replicas' views.
2
+
3
+ use crate::{Escrow, Mark, Refusal};
4
+ use core::cmp::Ordering;
5
+ use merge_machines::Merge;
6
+
7
+ impl<const N: usize> Escrow<N> {
8
+ /// Folds another replica's view into this one. Commutative, associative
9
+ /// and idempotent across the views of one deployment.
10
+ ///
11
+ /// # Errors
12
+ ///
13
+ /// [`Refusal::ConfigMismatch`] when `other` was built from a different
14
+ /// allotment. [`Refusal::Diverged`] when `other` records more spends,
15
+ /// refunds or outgoing transfers for the local replica than the local
16
+ /// replica remembers making (it lost state it had already shown to a peer),
17
+ /// or when the two views disagree about a transfer: one id with another
18
+ /// amount or cumulative total, or a newer id whose total does not cover
19
+ /// the older one.
20
+ /// [`Refusal::Overflow`] when the local balance would pass [`u64::MAX`].
21
+ /// The state is untouched on refusal.
22
+ pub fn merge(&mut self, other: &Self) -> Result<(), Refusal> {
23
+ self.join(other, true)
24
+ }
25
+
26
+ /// Folds `other` in like [`merge`](Self::merge), but adopts what `other`
27
+ /// knows about the local replica's own cells instead of refusing.
28
+ ///
29
+ /// This is the explicit way back for a replica that lost state. It
30
+ /// restores only what some peer had already seen: a spend or transfer that
31
+ /// was acted on but never left the lost replica is gone, and the caller
32
+ /// owns the consequences of that.
33
+ ///
34
+ /// # Errors
35
+ ///
36
+ /// [`Refusal::ConfigMismatch`], [`Refusal::Diverged`] when the two views
37
+ /// disagree about a transfer as in [`merge`](Self::merge), [`Refusal::Overdrawn`]
38
+ /// when the adopted history shows the local replica gave away or spent
39
+ /// more than it held, or [`Refusal::Overflow`]. The state is untouched on
40
+ /// refusal.
41
+ pub fn recover(&mut self, other: &Self) -> Result<(), Refusal> {
42
+ self.join(other, false)
43
+ }
44
+
45
+ fn join(&mut self, other: &Self, strict: bool) -> Result<(), Refusal> {
46
+ if self.replicas != other.replicas || self.allotted != other.allotted {
47
+ return Err(Refusal::ConfigMismatch);
48
+ }
49
+ if strict && self.outrun_by(other) {
50
+ return Err(Refusal::Diverged);
51
+ }
52
+ let cells = (self.grants.iter().zip(&other.grants))
53
+ .flat_map(|(mine, theirs)| mine.counts().iter().zip(theirs.counts()));
54
+ let marks = (self.marks.iter().zip(&other.marks))
55
+ .flat_map(|(mine, theirs)| mine.iter().zip(theirs));
56
+ if !cells
57
+ .zip(marks)
58
+ .all(|((held, seen), (mine, theirs))| agree((*mine, *held), (*theirs, *seen)))
59
+ {
60
+ return Err(Refusal::Diverged);
61
+ }
62
+ let mut next = *self;
63
+ next.spent.join(&other.spent);
64
+ next.refunded.join(&other.refunded);
65
+ for (mine, theirs) in next.grants.iter_mut().zip(&other.grants) {
66
+ mine.join(theirs);
67
+ }
68
+ let pairs = next.marks.iter_mut().zip(&other.marks);
69
+ for (mine, theirs) in pairs.flat_map(|(mine, theirs)| mine.iter_mut().zip(theirs)) {
70
+ *mine = (*mine).max(*theirs);
71
+ }
72
+ let balance = next.signed_balance(next.local);
73
+ if balance < 0 {
74
+ return Err(Refusal::Overdrawn);
75
+ }
76
+ if balance > i128::from(u64::MAX) {
77
+ return Err(Refusal::Overflow);
78
+ }
79
+ *self = next;
80
+ Ok(())
81
+ }
82
+
83
+ /// Whether `other` holds more in the cells only the local replica writes.
84
+ fn outrun_by(&self, other: &Self) -> bool {
85
+ let local = self.local;
86
+ let ahead = |mine: &[u64], theirs: &[u64]| theirs.iter().zip(mine).any(|(t, m)| t > m);
87
+ other.spent.count(local) > self.spent.count(local)
88
+ || other.refunded.count(local) > self.refunded.count(local)
89
+ || ahead(
90
+ local.of(&self.grants).counts(),
91
+ local.of(&other.grants).counts(),
92
+ )
93
+ || local
94
+ .of(&self.marks)
95
+ .iter()
96
+ .zip(local.of(&other.marks))
97
+ .any(|(mine, theirs)| theirs > mine)
98
+ }
99
+ }
100
+
101
+ /// Whether two views' knowledge of one `(from, to)` pair, each a latest mark
102
+ /// and the cumulative grant it left, could come from one history.
103
+ ///
104
+ /// A mark's grant cell is the cumulative total at that transfer. One id must
105
+ /// carry one amount and one total; a newer id's total must cover the older
106
+ /// total plus the newer amount, because ids strictly increase per pair.
107
+ fn agree(left: (Option<Mark>, u64), right: (Option<Mark>, u64)) -> bool {
108
+ // A pair with no mark has no grant (`decode` checks it): nothing to
109
+ // contradict.
110
+ let ((Some(mine), held), (Some(theirs), seen)) = (left, right) else {
111
+ return true;
112
+ };
113
+ match mine.id.cmp(&theirs.id) {
114
+ Ordering::Equal => mine.amount == theirs.amount && held == seen,
115
+ Ordering::Less => seen
116
+ .checked_sub(theirs.amount)
117
+ .is_some_and(|before| held <= before),
118
+ Ordering::Greater => held
119
+ .checked_sub(mine.amount)
120
+ .is_some_and(|before| seen <= before),
121
+ }
122
+ }
123
+
124
+ impl<const N: usize> Merge for Escrow<N> {
125
+ type Error = Refusal;
126
+
127
+ /// The same join as [`Escrow::merge`], which leaves the state untouched
128
+ /// when it refuses.
129
+ fn merge(&mut self, other: &Self) -> Result<(), Self::Error> {
130
+ Self::merge(self, other)
131
+ }
132
+ }