txn-core 0.1.3

The structs and traits for the `txn` and `async-txn` crates.
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
use core::{borrow::Borrow, future::Future, hash::Hash, ops::RangeBounds};

use super::{
  sync::*,
  types::{Entry, EntryValue},
};

/// A marker used to mark the keys that are read.
pub struct AsyncMarker<'a, C> {
  marker: &'a mut C,
}

impl<'a, C> AsyncMarker<'a, C> {
  /// Returns a new marker.
  #[inline]
  pub fn new(marker: &'a mut C) -> Self {
    Self { marker }
  }
}

impl<'a, C: AsyncCm> AsyncMarker<'a, C> {
  /// Marks a key is operated.
  pub async fn mark(&mut self, k: &C::Key) {
    self.marker.mark_read(k).await;
  }

  /// Marks a key is conflicted.
  pub async fn mark_conflict(&mut self, k: &C::Key) {
    self.marker.mark_conflict(k).await;
  }
}

impl<'a, C: AsyncCmRange> AsyncMarker<'a, C> {
  /// Marks a range is operated.
  pub async fn mark_range(&mut self, range: impl RangeBounds<C::Key>) {
    self.marker.mark_range(range).await;
  }
}

impl<'a, C: CmRange> AsyncMarker<'a, C> {
  /// Marks a range is operated.
  pub fn mark_range_blocking(&mut self, range: impl RangeBounds<C::Key>) {
    self.marker.mark_range(range);
  }
}

impl<'a, C: AsyncCmEquivalentRange> AsyncMarker<'a, C> {
  /// Marks a range is operated.
  pub async fn mark_range_equivalent<Q>(&mut self, range: impl RangeBounds<Q>)
  where
    C::Key: Borrow<Q>,
    Q: Hash + Eq + ?Sized,
  {
    self.marker.mark_range_equivalent(range).await;
  }
}

impl<'a, C: CmEquivalentRange> AsyncMarker<'a, C> {
  /// Marks a range is operated.
  pub fn mark_range_equivalent_blocking<Q>(&mut self, range: impl RangeBounds<Q>)
  where
    C::Key: Borrow<Q>,
    Q: Hash + Eq + ?Sized,
  {
    self.marker.mark_range_equivalent(range);
  }
}

impl<'a, C: AsyncCmComparableRange> AsyncMarker<'a, C> {
  /// Marks a range is operated.
  pub async fn mark_range_comparable<Q>(&mut self, range: impl RangeBounds<Q>)
  where
    C::Key: Borrow<Q>,
    Q: Ord + ?Sized,
  {
    self.marker.mark_range_comparable(range).await;
  }
}

impl<'a, C: CmComparableRange> AsyncMarker<'a, C> {
  /// Marks a range is operated.
  pub fn mark_range_comparable_blocking<Q>(&mut self, range: impl RangeBounds<Q>)
  where
    C::Key: Borrow<Q>,
    Q: Ord + ?Sized,
  {
    self.marker.mark_range_comparable(range);
  }
}

impl<'a, C: AsyncCmComparable> AsyncMarker<'a, C> {
  /// Marks a key is operated.
  pub async fn mark_comparable<Q>(&mut self, k: &Q)
  where
    C::Key: Borrow<Q>,
    Q: Ord + ?Sized,
  {
    self.marker.mark_read_comparable(k).await;
  }

  /// Marks a key is conflicted.
  pub async fn mark_conflict_comparable<Q>(&mut self, k: &Q)
  where
    C::Key: Borrow<Q>,
    Q: Ord + ?Sized,
  {
    self.marker.mark_conflict_comparable(k).await;
  }
}

impl<'a, C: AsyncCmEquivalent> AsyncMarker<'a, C> {
  /// Marks a key is operated.
  pub async fn mark_equivalent<Q>(&mut self, k: &Q)
  where
    C::Key: Borrow<Q>,
    Q: Hash + Eq + ?Sized,
  {
    self.marker.mark_read_equivalent(k).await;
  }

  /// Marks a key is conflicted.
  pub async fn mark_conflict_equivalent<Q>(&mut self, k: &Q)
  where
    C::Key: Borrow<Q>,
    Q: Hash + Eq + ?Sized,
  {
    self.marker.mark_conflict_equivalent(k).await;
  }
}

impl<'a, C: Cm> AsyncMarker<'a, C> {
  /// Marks a key is operated.
  pub fn mark_blocking(&mut self, k: &C::Key) {
    self.marker.mark_read(k);
  }

  /// Marks a key is conflicted.
  pub fn mark_conflict_blocking(&mut self, k: &C::Key) {
    self.marker.mark_conflict(k);
  }
}

impl<'a, C: CmComparable> AsyncMarker<'a, C> {
  /// Marks a key is operated.
  pub fn mark_comparable_blocking<Q>(&mut self, k: &Q)
  where
    C::Key: Borrow<Q>,
    Q: Ord + ?Sized,
  {
    self.marker.mark_read_comparable(k);
  }

  /// Marks a key is conflicted.
  pub fn mark_conflict_comparable_blocking<Q>(&mut self, k: &Q)
  where
    C::Key: Borrow<Q>,
    Q: Ord + ?Sized,
  {
    self.marker.mark_conflict_comparable(k);
  }
}

impl<'a, C: CmEquivalent> AsyncMarker<'a, C> {
  /// Marks a key is operated.
  pub fn mark_equivalent_blocking<Q>(&mut self, k: &Q)
  where
    C::Key: Borrow<Q>,
    Q: Hash + Eq + ?Sized,
  {
    self.marker.mark_read_equivalent(k);
  }

  /// Marks a key is conflicted.
  pub fn mark_conflict_equivalent_blocking<Q>(&mut self, k: &Q)
  where
    C::Key: Borrow<Q>,
    Q: Hash + Eq + ?Sized,
  {
    self.marker.mark_conflict_equivalent(k);
  }
}

/// The conflict manager that can be used to manage the conflicts in a transaction.
///
/// The conflict normally needs to have:
///
/// 1. Contains fingerprints of keys read.
/// 2. Contains fingerprints of keys written. This is used for conflict detection.
pub trait AsyncCm: Sized {
  /// The error type returned by the conflict manager.
  type Error: crate::error::Error;

  /// The key type.
  type Key;

  /// The options type used to create the conflict manager.
  type Options;

  /// Create a new conflict manager with the given options.
  fn new(options: Self::Options) -> impl Future<Output = Result<Self, Self::Error>>;

  /// Mark the key is read.
  fn mark_read(&mut self, key: &Self::Key) -> impl Future<Output = ()>;

  /// Mark the key is .
  fn mark_conflict(&mut self, key: &Self::Key) -> impl Future<Output = ()>;

  /// Returns true if we have a conflict.
  fn has_conflict(&self, other: &Self) -> impl Future<Output = bool>;

  /// Rollback the conflict manager.
  fn rollback(&mut self) -> impl Future<Output = Result<(), Self::Error>>;
}

/// A extended trait of the [`AsyncCm`] trait that can be used to manage the range of keys.
pub trait AsyncCmRange: Cm + Sized {
  /// Mark the range is read.
  fn mark_range(&mut self, range: impl RangeBounds<<Self as Cm>::Key>) -> impl Future<Output = ()>;
}

/// An optimized version of the [`AsyncCmRange`] trait that if your conflict manager is depend on hash.
pub trait AsyncCmEquivalentRange: AsyncCmRange + Sized {
  /// Mark the range is read.
  fn mark_range_equivalent<Q>(&mut self, range: impl RangeBounds<Q>) -> impl Future<Output = ()>
  where
    Self::Key: Borrow<Q>,
    Q: Hash + Eq + ?Sized;
}

/// An optimized version of the [`AsyncCmRange`] trait that if your conflict manager is depend on the order.
pub trait AsyncCmComparableRange: AsyncCmRange + CmComparable {
  /// Mark the range is read.
  fn mark_range_comparable<Q>(&mut self, range: impl RangeBounds<Q>) -> impl Future<Output = ()>
  where
    Self::Key: Borrow<Q>,
    Q: Ord + ?Sized;
}

/// An optimized version of the [`AsyncCm`] trait that if your conflict manager is depend on hash.
pub trait AsyncCmEquivalent: AsyncCm {
  /// Optimized version of [`mark_read`] that accepts borrowed keys. Optional to implement.
  fn mark_read_equivalent<Q>(&mut self, key: &Q) -> impl Future<Output = ()>
  where
    Self::Key: Borrow<Q>,
    Q: Hash + Eq + ?Sized;

  /// Optimized version of [`mark_conflict`] that accepts borrowed keys. Optional to implement.
  fn mark_conflict_equivalent<Q>(&mut self, key: &Q) -> impl Future<Output = ()>
  where
    Self::Key: Borrow<Q>,
    Q: Hash + Eq + ?Sized;
}

/// An optimized version of the [`AsyncCm`] trait that if your conflict manager is depend on the order.
pub trait AsyncCmComparable: AsyncCm {
  /// Optimized version of [`mark_read`] that accepts borrowed keys. Optional to implement.
  fn mark_read_comparable<Q>(&mut self, key: &Q) -> impl Future<Output = ()>
  where
    Self::Key: Borrow<Q>,
    Q: Ord + ?Sized;

  /// Optimized version of [`mark_conflict`] that accepts borrowed keys. Optional to implement.
  fn mark_conflict_comparable<Q>(&mut self, key: &Q) -> impl Future<Output = ()>
  where
    Self::Key: Borrow<Q>,
    Q: Ord + ?Sized;
}

/// A pending writes manager that can be used to store pending writes in a transaction.
///
/// By default, there are two implementations of this trait:
/// - [`IndexMap`]: A hash map with consistent ordering and fast lookups.
/// - [`BTreeMap`]: A balanced binary tree with ordered keys and fast lookups.
///
/// But, users can create their own implementations by implementing this trait.
/// e.g. if you want to implement a recovery transaction manager, you can use a persistent
/// storage to store the pending writes.
pub trait AsyncPwm: Sized {
  /// The error type returned by the conflict manager.
  type Error: crate::error::Error;
  /// The key type.
  type Key;
  /// The value type.
  type Value;
  /// The options type used to create the pending manager.
  type Options;
  /// The iterator type that borrows the pending writes.
  type Iter<'a>: Iterator<Item = (&'a Self::Key, &'a EntryValue<Self::Value>)>
  where
    Self: 'a;
  /// The iterator type that consumes the pending writes.
  type IntoIter: Iterator<Item = (Self::Key, EntryValue<Self::Value>)>;

  /// Create a new pending manager with the given options.
  fn new(options: Self::Options) -> impl Future<Output = Result<Self, Self::Error>>;

  /// Returns true if the buffer is empty.
  fn is_empty(&self) -> impl Future<Output = bool>;

  /// Returns the number of elements in the buffer.
  fn len(&self) -> impl Future<Output = usize>;

  /// Validate if the entry is valid for this database.
  ///
  /// e.g.
  /// - If the entry is expired
  /// - If the key or the value is too large
  /// - If the key or the value is empty
  /// - If the key or the value contains invalid characters
  /// - and etc.
  fn validate_entry(
    &self,
    entry: &Entry<Self::Key, Self::Value>,
  ) -> impl Future<Output = Result<(), Self::Error>>;

  /// Returns the maximum batch size in bytes
  fn max_batch_size(&self) -> u64;

  /// Returns the maximum entries in batch
  fn max_batch_entries(&self) -> u64;

  /// Returns the estimated size of the entry in bytes when persisted in the database.
  fn estimate_size(&self, entry: &Entry<Self::Key, Self::Value>) -> u64;

  /// Returns a reference to the value corresponding to the key.
  fn get(
    &self,
    key: &Self::Key,
  ) -> impl Future<Output = Result<Option<&EntryValue<Self::Value>>, Self::Error>>;

  /// Returns a reference to the key-value pair corresponding to the key.
  fn get_entry(
    &self,
    key: &Self::Key,
  ) -> impl Future<Output = Result<Option<(&Self::Key, &EntryValue<Self::Value>)>, Self::Error>>;

  /// Returns true if the pending manager contains the key.
  fn contains_key(&self, key: &Self::Key) -> impl Future<Output = Result<bool, Self::Error>>;

  /// Inserts a key-value pair into the er.
  fn insert(
    &mut self,
    key: Self::Key,
    value: EntryValue<Self::Value>,
  ) -> impl Future<Output = Result<(), Self::Error>>;

  /// Removes a key from the pending writes, returning the key-value pair if the key was previously in the pending writes.
  fn remove_entry(
    &mut self,
    key: &Self::Key,
  ) -> impl Future<Output = Result<Option<(Self::Key, EntryValue<Self::Value>)>, Self::Error>>;

  /// Rollback the pending writes.
  fn rollback(&mut self) -> impl Future<Output = Result<(), Self::Error>>;

  /// Returns an iterator over the pending writes.
  fn iter(&self) -> impl Future<Output = Self::Iter<'_>>;

  /// Returns an iterator that consumes the pending writes.
  fn into_iter(self) -> impl Future<Output = Self::IntoIter>;
}

/// An trait that can be used to get a range over the pending writes.
pub trait AsyncPwmRange: AsyncPwm {
  /// The iterator type.
  type Range<'a>: IntoIterator<Item = (&'a Self::Key, &'a EntryValue<Self::Value>)>
  where
    Self: 'a;

  /// Returns an iterator over the pending writes.
  fn range<R: RangeBounds<Self::Key>>(&self, range: R) -> impl Future<Output = Self::Range<'_>>;
}

/// An trait that can be used to get a range over the pending writes.
pub trait AsyncPwmComparableRange: AsyncPwmRange + AsyncPwmComparable {
  /// Returns an iterator over the pending writes.
  fn range_comparable<T, R>(&self, range: R) -> impl Future<Output = Self::Range<'_>>
  where
    T: ?Sized + Ord,
    Self::Key: Borrow<T> + Ord,
    R: RangeBounds<T>;
}

/// An trait that can be used to get a range over the pending writes.
pub trait AsyncPwmEquivalentRange: AsyncPwmRange + AsyncPwmEquivalent {
  /// Returns an iterator over the pending writes.
  fn range_equivalent<T, R>(&self, range: R) -> impl Future<Output = Self::Range<'_>>
  where
    T: ?Sized + Eq + Hash,
    Self::Key: Borrow<T> + Eq + Hash,
    R: RangeBounds<T>;
}

/// An optimized version of the [`AsyncPwm`] trait that if your pending writes manager is depend on hash.
pub trait AsyncPwmEquivalent: AsyncPwm {
  /// Optimized version of [`AsyncPwm::get`] that accepts borrowed keys.
  fn get_equivalent<Q>(
    &self,
    key: &Q,
  ) -> impl Future<Output = Result<Option<&EntryValue<Self::Value>>, Self::Error>>
  where
    Self::Key: Borrow<Q>,
    Q: Hash + Eq + ?Sized;

  /// Optimized version of [`AsyncPwm::get_entry`] that accepts borrowed keys.
  fn get_entry_equivalent<Q>(
    &self,
    key: &Q,
  ) -> impl Future<Output = Result<Option<(&Self::Key, &EntryValue<Self::Value>)>, Self::Error>>
  where
    Self::Key: Borrow<Q>,
    Q: Hash + Eq + ?Sized;

  /// Optimized version of [`AsyncPwm::contains_key`] that accepts borrowed keys.
  fn contains_key_equivalent<Q>(&self, key: &Q) -> impl Future<Output = Result<bool, Self::Error>>
  where
    Self::Key: Borrow<Q>,
    Q: Hash + Eq + ?Sized;

  /// Optimized version of [`AsyncPwm::remove_entry`] that accepts borrowed keys.
  fn remove_entry_equivalent<Q>(
    &mut self,
    key: &Q,
  ) -> impl Future<Output = Result<Option<(Self::Key, EntryValue<Self::Value>)>, Self::Error>>
  where
    Self::Key: Borrow<Q>,
    Q: Hash + Eq + ?Sized;
}

/// An optimized version of the [`AsyncPwm`] trait that if your pending writes manager is depend on the order.
pub trait AsyncPwmComparable: AsyncPwm {
  /// Optimized version of [`AsyncPwm::get`] that accepts borrowed keys.
  fn get_comparable<Q>(
    &self,
    key: &Q,
  ) -> impl Future<Output = Result<Option<&EntryValue<Self::Value>>, Self::Error>>
  where
    Self::Key: Borrow<Q>,
    Q: Ord + ?Sized;

  /// Optimized version of [`AsyncPwm::get_entry`] that accepts borrowed keys.
  fn get_entry_comparable<Q>(
    &self,
    key: &Q,
  ) -> impl Future<Output = Result<Option<(&Self::Key, &EntryValue<Self::Value>)>, Self::Error>>
  where
    Self::Key: Borrow<Q>,
    Q: Ord + ?Sized;

  /// Optimized version of [`AsyncPwm::contains_key`] that accepts borrowed keys.
  fn contains_key_comparable<Q>(&self, key: &Q) -> impl Future<Output = Result<bool, Self::Error>>
  where
    Self::Key: Borrow<Q>,
    Q: Ord + ?Sized;

  /// Optimized version of [`AsyncPwm::remove_entry`] that accepts borrowed keys.
  fn remove_entry_comparable<Q>(
    &mut self,
    key: &Q,
  ) -> impl Future<Output = Result<Option<(Self::Key, EntryValue<Self::Value>)>, Self::Error>>
  where
    Self::Key: Borrow<Q>,
    Q: Ord + ?Sized;
}

impl<T> AsyncCm for T
where
  T: Cm,
{
  type Error = <T as Cm>::Error;

  type Key = <T as Cm>::Key;

  type Options = <T as Cm>::Options;

  async fn new(options: Self::Options) -> Result<Self, Self::Error> {
    <T as Cm>::new(options)
  }

  async fn mark_read(&mut self, key: &Self::Key) {
    <T as Cm>::mark_read(self, key)
  }

  async fn mark_conflict(&mut self, key: &Self::Key) {
    <T as Cm>::mark_conflict(self, key)
  }

  async fn has_conflict(&self, other: &Self) -> bool {
    <T as Cm>::has_conflict(self, other)
  }

  async fn rollback(&mut self) -> Result<(), Self::Error> {
    <T as Cm>::rollback(self)
  }
}

impl<T> AsyncCmComparable for T
where
  T: CmComparable,
{
  async fn mark_read_comparable<Q>(&mut self, key: &Q)
  where
    Self::Key: Borrow<Q>,
    Q: Ord + ?Sized,
  {
    <T as CmComparable>::mark_read_comparable(self, key)
  }

  async fn mark_conflict_comparable<Q>(&mut self, key: &Q)
  where
    Self::Key: Borrow<Q>,
    Q: Ord + ?Sized,
  {
    <T as CmComparable>::mark_conflict_comparable(self, key)
  }
}

impl<T> AsyncCmEquivalent for T
where
  T: CmEquivalent,
{
  async fn mark_read_equivalent<Q>(&mut self, key: &Q)
  where
    Self::Key: Borrow<Q>,
    Q: Hash + Eq + ?Sized,
  {
    <T as CmEquivalent>::mark_read_equivalent(self, key)
  }

  async fn mark_conflict_equivalent<Q>(&mut self, key: &Q)
  where
    Self::Key: Borrow<Q>,
    Q: Hash + Eq + ?Sized,
  {
    <T as CmEquivalent>::mark_conflict_equivalent(self, key)
  }
}

impl<T> AsyncPwm for T
where
  T: Pwm,
{
  type Error = <T as Pwm>::Error;

  type Key = <T as Pwm>::Key;

  type Value = <T as Pwm>::Value;

  type Options = <T as Pwm>::Options;

  type Iter<'a> = <T as Pwm>::Iter<'a> where Self: 'a;

  type IntoIter = <T as Pwm>::IntoIter;

  async fn new(options: Self::Options) -> Result<Self, Self::Error> {
    <T as Pwm>::new(options)
  }

  async fn is_empty(&self) -> bool {
    <T as Pwm>::is_empty(self)
  }

  async fn len(&self) -> usize {
    <T as Pwm>::len(self)
  }

  async fn validate_entry(&self, entry: &Entry<Self::Key, Self::Value>) -> Result<(), Self::Error> {
    <T as Pwm>::validate_entry(self, entry)
  }

  fn max_batch_size(&self) -> u64 {
    <T as Pwm>::max_batch_size(self)
  }

  fn max_batch_entries(&self) -> u64 {
    <T as Pwm>::max_batch_entries(self)
  }

  fn estimate_size(&self, entry: &Entry<Self::Key, Self::Value>) -> u64 {
    <T as Pwm>::estimate_size(self, entry)
  }

  async fn get(&self, key: &Self::Key) -> Result<Option<&EntryValue<Self::Value>>, Self::Error> {
    <T as Pwm>::get(self, key)
  }

  async fn get_entry(
    &self,
    key: &Self::Key,
  ) -> Result<Option<(&Self::Key, &EntryValue<Self::Value>)>, Self::Error> {
    <T as Pwm>::get_entry(self, key)
  }

  async fn contains_key(&self, key: &Self::Key) -> Result<bool, Self::Error> {
    <T as Pwm>::contains_key(self, key)
  }

  async fn insert(
    &mut self,
    key: Self::Key,
    value: EntryValue<Self::Value>,
  ) -> Result<(), Self::Error> {
    <T as Pwm>::insert(self, key, value)
  }

  async fn remove_entry(
    &mut self,
    key: &Self::Key,
  ) -> Result<Option<(Self::Key, EntryValue<Self::Value>)>, Self::Error> {
    <T as Pwm>::remove_entry(self, key)
  }

  async fn rollback(&mut self) -> Result<(), Self::Error> {
    <T as Pwm>::rollback(self)
  }

  async fn iter(&self) -> Self::Iter<'_> {
    <T as Pwm>::iter(self)
  }

  async fn into_iter(self) -> Self::IntoIter {
    <T as Pwm>::into_iter(self)
  }
}

impl<T> AsyncPwmRange for T
where
  T: PwmRange,
{
  type Range<'a> = <T as PwmRange>::Range<'a> where Self: 'a;

  async fn range<R: RangeBounds<Self::Key>>(&self, range: R) -> Self::Range<'_> {
    <T as PwmRange>::range(self, range)
  }
}

impl<C> AsyncPwmComparableRange for C
where
  C: PwmComparableRange,
{
  async fn range_comparable<T, R>(&self, range: R) -> Self::Range<'_>
  where
    T: ?Sized + Ord,
    Self::Key: Borrow<T> + Ord,
    R: RangeBounds<T>,
  {
    <C as PwmComparableRange>::range_comparable(self, range)
  }
}

impl<C> AsyncPwmEquivalentRange for C
where
  C: PwmEquivalentRange,
{
  async fn range_equivalent<T, R>(&self, range: R) -> Self::Range<'_>
  where
    T: ?Sized + Eq + Hash,
    Self::Key: Borrow<T> + Eq + Hash,
    R: RangeBounds<T>,
  {
    <C as PwmEquivalentRange>::range_equivalent(self, range)
  }
}

impl<T> AsyncPwmComparable for T
where
  T: PwmComparable,
{
  async fn get_comparable<Q>(
    &self,
    key: &Q,
  ) -> Result<Option<&EntryValue<Self::Value>>, Self::Error>
  where
    Self::Key: Borrow<Q>,
    Q: Ord + ?Sized,
  {
    <T as PwmComparable>::get_comparable(self, key)
  }

  async fn get_entry_comparable<Q>(
    &self,
    key: &Q,
  ) -> Result<Option<(&Self::Key, &EntryValue<Self::Value>)>, Self::Error>
  where
    Self::Key: Borrow<Q>,
    Q: Ord + ?Sized,
  {
    <T as PwmComparable>::get_entry_comparable(self, key)
  }

  async fn contains_key_comparable<Q>(&self, key: &Q) -> Result<bool, Self::Error>
  where
    Self::Key: Borrow<Q>,
    Q: Ord + ?Sized,
  {
    <T as PwmComparable>::contains_key_comparable(self, key)
  }

  async fn remove_entry_comparable<Q>(
    &mut self,
    key: &Q,
  ) -> Result<Option<(Self::Key, EntryValue<Self::Value>)>, Self::Error>
  where
    Self::Key: Borrow<Q>,
    Q: Ord + ?Sized,
  {
    <T as PwmComparable>::remove_entry_comparable(self, key)
  }
}

impl<T> AsyncPwmEquivalent for T
where
  T: PwmEquivalent,
{
  async fn get_equivalent<Q>(
    &self,
    key: &Q,
  ) -> Result<Option<&EntryValue<Self::Value>>, Self::Error>
  where
    Self::Key: Borrow<Q>,
    Q: Hash + Eq + ?Sized,
  {
    <T as PwmEquivalent>::get_equivalent(self, key)
  }

  async fn get_entry_equivalent<Q>(
    &self,
    key: &Q,
  ) -> Result<Option<(&Self::Key, &EntryValue<Self::Value>)>, Self::Error>
  where
    Self::Key: Borrow<Q>,
    Q: Hash + Eq + ?Sized,
  {
    <T as PwmEquivalent>::get_entry_equivalent(self, key)
  }

  async fn contains_key_equivalent<Q>(&self, key: &Q) -> Result<bool, Self::Error>
  where
    Self::Key: Borrow<Q>,
    Q: Hash + Eq + ?Sized,
  {
    <T as PwmEquivalent>::contains_key_equivalent(self, key)
  }

  async fn remove_entry_equivalent<Q>(
    &mut self,
    key: &Q,
  ) -> Result<Option<(Self::Key, EntryValue<Self::Value>)>, Self::Error>
  where
    Self::Key: Borrow<Q>,
    Q: Hash + Eq + ?Sized,
  {
    <T as PwmEquivalent>::remove_entry_equivalent(self, key)
  }
}