1- //! This module is home to the [`Persist `] trait which defines the behavior of a data store
1+ //! This module is home to the [`PersistBackend `] trait which defines the behavior of a data store
22//! required to persist changes made to BDK data structures.
33//!
4- //! The [`StagedPersist `] type provides a convenient wrapper around implementations of [`Persist `] that
4+ //! The [`StagedPersistBackend `] type provides a convenient wrapper around implementations of [`PersistBackend `] that
55//! allows changes to be staged before committing them.
66//!
77//! The [`CombinedChangeSet`] type encapsulates a combination of [`crate`] structures that are
@@ -92,7 +92,7 @@ impl<K, A> From<indexed_tx_graph::ChangeSet<A, keychain::ChangeSet<K>>>
9292///
9393/// `C` represents the changeset; a datatype that records changes made to in-memory data structures
9494/// that are to be persisted, or retrieved from persistence.
95- pub trait Persist < C > {
95+ pub trait PersistBackend < C > {
9696 /// The error the backend returns when it fails to write.
9797 type WriteError : Debug + Display ;
9898
@@ -113,7 +113,7 @@ pub trait Persist<C> {
113113 fn load_changes ( & mut self ) -> Result < Option < C > , Self :: LoadError > ;
114114}
115115
116- impl < C > Persist < C > for ( ) {
116+ impl < C > PersistBackend < C > for ( ) {
117117 type WriteError = Infallible ;
118118 type LoadError = Infallible ;
119119
@@ -132,7 +132,7 @@ impl<C> Persist<C> for () {
132132/// `C` represents the changeset; a datatype that records changes made to in-memory data structures
133133/// that are to be persisted, or retrieved from persistence.
134134#[ async_trait]
135- pub trait PersistAsync < C > {
135+ pub trait PersistBackendAsync < C > {
136136 /// The error the backend returns when it fails to write.
137137 type WriteError : Debug + Display ;
138138
@@ -155,7 +155,7 @@ pub trait PersistAsync<C> {
155155
156156#[ cfg( feature = "async" ) ]
157157#[ async_trait]
158- impl < C > PersistAsync < C > for ( ) {
158+ impl < C > PersistBackendAsync < C > for ( ) {
159159 type WriteError = Infallible ;
160160 type LoadError = Infallible ;
161161
@@ -168,17 +168,17 @@ impl<C> PersistAsync<C> for () {
168168 }
169169}
170170
171- /// `StagedPersist ` adds a convenient staging area for changesets before they are persisted.
171+ /// `StagedPersistBackend ` adds a convenient staging area for changesets before they are persisted.
172172///
173173/// Not all changes to the in-memory representation needs to be written to disk right away, so
174- /// [`crate::persist::StagedPersist ::stage`] can be used to *stage* changes first and then
175- /// [`crate::persist::StagedPersist ::commit`] can be used to write changes to disk.
176- pub struct StagedPersist < C , P : Persist < C > > {
174+ /// [`crate::persist::StagedPersistBackend ::stage`] can be used to *stage* changes first and then
175+ /// [`crate::persist::StagedPersistBackend ::commit`] can be used to write changes to disk.
176+ pub struct StagedPersistBackend < C , P : PersistBackend < C > > {
177177 inner : P ,
178178 stage : C ,
179179}
180180
181- impl < C , P : Persist < C > > Persist < C > for StagedPersist < C , P > {
181+ impl < C , P : PersistBackend < C > > PersistBackend < C > for StagedPersistBackend < C , P > {
182182 type WriteError = P :: WriteError ;
183183 type LoadError = P :: LoadError ;
184184
@@ -191,16 +191,16 @@ impl<C, P: Persist<C>> Persist<C> for StagedPersist<C, P> {
191191 }
192192}
193193
194- impl < C , P > StagedPersist < C , P >
194+ impl < C , P > StagedPersistBackend < C , P >
195195where
196196 C : Default + Append ,
197- P : Persist < C > ,
197+ P : PersistBackend < C > ,
198198{
199- /// Create a new [`StagedPersist `] adding staging to an inner data store that implements
200- /// [`Persist `].
201- pub fn new ( persist : P ) -> Self {
199+ /// Create a new [`StagedPersistBackend `] adding staging to an inner data store that implements
200+ /// [`PersistBackend `].
201+ pub fn new ( persist_backend : P ) -> Self {
202202 Self {
203- inner : persist ,
203+ inner : persist_backend ,
204204 stage : Default :: default ( ) ,
205205 }
206206 }
@@ -258,16 +258,18 @@ where
258258/// `StagedPersistAsync` adds a convenient async staging area for changesets before they are persisted.
259259///
260260/// Not all changes to the in-memory representation needs to be written to disk right away, so
261- /// [`StagedPersistAsync ::stage`] can be used to *stage* changes first and then
262- /// [`StagedPersistAsync ::commit`] can be used to write changes to disk.
263- pub struct StagedPersistAsync < C , P : PersistAsync < C > > {
261+ /// [`StagedPersistBackendAsync ::stage`] can be used to *stage* changes first and then
262+ /// [`StagedPersistBackendAsync ::commit`] can be used to write changes to disk.
263+ pub struct StagedPersistBackendAsync < C , P : PersistBackendAsync < C > > {
264264 inner : P ,
265265 staged : C ,
266266}
267267
268268#[ cfg( feature = "async" ) ]
269269#[ async_trait]
270- impl < C : Send + Sync , P : PersistAsync < C > + Send > PersistAsync < C > for StagedPersistAsync < C , P > {
270+ impl < C : Send + Sync , P : PersistBackendAsync < C > + Send > PersistBackendAsync < C >
271+ for StagedPersistBackendAsync < C , P >
272+ {
271273 type WriteError = P :: WriteError ;
272274 type LoadError = P :: LoadError ;
273275
@@ -281,16 +283,16 @@ impl<C: Send + Sync, P: PersistAsync<C> + Send> PersistAsync<C> for StagedPersis
281283}
282284
283285#[ cfg( feature = "async" ) ]
284- impl < C , P > StagedPersistAsync < C , P >
286+ impl < C , P > StagedPersistBackendAsync < C , P >
285287where
286288 C : Default + Append + Send + Sync ,
287- P : PersistAsync < C > + Send ,
289+ P : PersistBackendAsync < C > + Send ,
288290{
289- /// Create a new [`StagedPersistAsync `] adding staging to an inner data store that implements
290- /// [`PersistAsync `].
291- pub fn new ( persist : P ) -> Self {
291+ /// Create a new [`StagedPersistBackendAsync `] adding staging to an inner data store that implements
292+ /// [`PersistBackendAsync `].
293+ pub fn new ( persist_backend : P ) -> Self {
292294 Self {
293- inner : persist ,
295+ inner : persist_backend ,
294296 staged : Default :: default ( ) ,
295297 }
296298 }
@@ -349,7 +351,7 @@ where
349351mod test {
350352 extern crate core;
351353
352- use crate :: persist:: { Persist , StagedPersist } ;
354+ use crate :: persist:: { PersistBackend , StagedPersistBackend } ;
353355 use crate :: Append ;
354356 use std:: error:: Error ;
355357 use std:: fmt:: { self , Display , Formatter } ;
@@ -395,7 +397,7 @@ mod test {
395397 }
396398 }
397399
398- impl < C > Persist < C > for TestBackend < C >
400+ impl < C > PersistBackend < C > for TestBackend < C >
399401 where
400402 C : Default + Append + Clone + ToString ,
401403 {
@@ -426,7 +428,7 @@ mod test {
426428 changeset : TestChangeSet ( None ) ,
427429 } ;
428430
429- let mut staged_backend = StagedPersist :: new ( backend) ;
431+ let mut staged_backend = StagedPersistBackend :: new ( backend) ;
430432 staged_backend. stage ( TestChangeSet ( Some ( "ONE" . to_string ( ) ) ) ) ;
431433 staged_backend. stage ( TestChangeSet ( None ) ) ;
432434 staged_backend. stage ( TestChangeSet ( Some ( "TWO" . to_string ( ) ) ) ) ;
@@ -446,7 +448,7 @@ mod test {
446448 let backend = TestBackend {
447449 changeset : TestChangeSet ( None ) ,
448450 } ;
449- let mut staged_backend = StagedPersist :: new ( backend) ;
451+ let mut staged_backend = StagedPersistBackend :: new ( backend) ;
450452 staged_backend. stage ( TestChangeSet ( Some ( "ERROR" . to_string ( ) ) ) ) ;
451453 let result = staged_backend. commit ( ) ;
452454 assert ! ( matches!( result, Err ( e) if e == FailedWrite ) ) ;
0 commit comments