@@ -5,20 +5,77 @@ use std::ops::RangeBounds;
55
66use crate :: tap_receipt:: ReceivedReceipt ;
77
8+ /// `ReceiptStorageAdapter` defines a trait for storage adapters to manage `ReceivedReceipt` data.
9+ ///
10+ /// This trait is designed to be implemented by users of this library who want to
11+ /// customize the storage behavior of `ReceivedReceipt` data. The error handling is also
12+ /// customizable by defining an `AdapterError` type, which must implement both `Error`
13+ /// and `Debug` from the standard library.
14+ ///
15+ /// # Usage
16+ ///
17+ /// The `store_receipt` method should be used to store a new `ReceivedReceipt` in the storage
18+ /// managed by the adapter. It returns a unique receipt_id associated with the stored receipt.
19+ /// Any errors during this operation should be captured and returned in the `AdapterError` format.
20+ ///
21+ /// The `retrieve_receipts_in_timestamp_range` method should be implemented to fetch all `ReceivedReceipts`
22+ /// within a specific timestamp range from the storage. The returned receipts should be in the form of a vector
23+ /// of tuples where each tuple contains the unique receipt_id and the corresponding `ReceivedReceipt`.
24+ ///
25+ /// The `update_receipt_by_id` method is designed to update a specific `ReceivedReceipt` identified by a unique
26+ /// receipt_id. Any errors during this operation should be captured and returned as an `AdapterError`.
27+ ///
28+ /// The `remove_receipts_in_timestamp_range` method is used to remove all `ReceivedReceipts` within a specific
29+ /// timestamp range from the storage. Any errors during this operation should be captured and returned as an `AdapterError`.
30+ ///
31+ /// This trait is utilized by [crate::tap_manager], which relies on these
32+ /// operations for working with `ReceivedReceipt` data.
33+ ///
34+ /// # Example
35+ ///
36+ /// For example code see [crate::adapters::receipt_storage_adapter_mock]
37+
838pub trait ReceiptStorageAdapter {
9- /// User defined error type;
39+ /// Defines the user-specified error type.
40+ ///
41+ /// This error type should implement the `Error` and `Debug` traits from the standard library.
42+ /// Errors of this type are returned to the user when an operation fails.
1043 type AdapterError : std:: error:: Error + std:: fmt:: Debug + Send + Sync + ' static ;
1144
45+ /// Stores a new `ReceivedReceipt` into the storage.
46+ ///
47+ /// This method should be implemented to store a new `ReceivedReceipt` into your chosen storage system.
48+ /// It returns a unique receipt_id associated with the stored receipt. Any errors that occur during
49+ /// this process should be captured and returned as an `AdapterError`.
1250 fn store_receipt ( & mut self , receipt : ReceivedReceipt ) -> Result < u64 , Self :: AdapterError > ;
51+
52+ /// Retrieves all `ReceivedReceipts` within a specific timestamp range.
53+ ///
54+ /// This method should be implemented to fetch all `ReceivedReceipts` within a specific timestamp range
55+ /// from your storage system. The returned receipts should be in the form of a vector of tuples where
56+ /// each tuple contains the unique receipt_id and the corresponding `ReceivedReceipt`.
57+ /// Any errors that occur during this process should be captured and returned as an `AdapterError`.
1358 fn retrieve_receipts_in_timestamp_range < R : RangeBounds < u64 > > (
1459 & self ,
1560 timestamp_range_ns : R ,
1661 ) -> Result < Vec < ( u64 , ReceivedReceipt ) > , Self :: AdapterError > ;
62+
63+ /// Updates a specific `ReceivedReceipt` identified by a unique receipt_id.
64+ ///
65+ /// This method should be implemented to update a specific `ReceivedReceipt` identified by a unique
66+ /// receipt_id in your storage system. Any errors that occur during this process should be captured
67+ /// and returned as an `AdapterError`.
1768 fn update_receipt_by_id (
1869 & mut self ,
1970 receipt_id : u64 ,
2071 receipt : ReceivedReceipt ,
2172 ) -> Result < ( ) , Self :: AdapterError > ;
73+
74+ /// Removes all `ReceivedReceipts` within a specific timestamp range from the storage.
75+ ///
76+ /// This method should be implemented to remove all `ReceivedReceipts` within a specific timestamp
77+ /// range from your storage system. Any errors that occur during this process should be captured and
78+ /// returned as an `AdapterError`.
2279 fn remove_receipts_in_timestamp_range < R : RangeBounds < u64 > > (
2380 & mut self ,
2481 timestamp_ns : R ,
0 commit comments