Skip to content

Commit 340808e

Browse files
evanlinjinnotmandatory
authored andcommitted
docs(wallet): fixes/improvements for persisted and params types
1 parent 9600293 commit 340808e

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

crates/wallet/src/wallet/params.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl CreateParams {
109109
self
110110
}
111111

112-
/// Create [`PersistedWallet`] with the given `Db`.
112+
/// Create [`PersistedWallet`] with the given [`WalletPersister`].
113113
pub fn create_wallet<P>(
114114
self,
115115
persister: &mut P,
@@ -120,7 +120,7 @@ impl CreateParams {
120120
PersistedWallet::create(persister, self)
121121
}
122122

123-
/// Create [`PersistedWallet`] with the given async `Db`.
123+
/// Create [`PersistedWallet`] with the given [`AsyncWalletPersister`].
124124
pub async fn create_wallet_async<P>(
125125
self,
126126
persister: &mut P,
@@ -220,7 +220,7 @@ impl LoadParams {
220220
self
221221
}
222222

223-
/// Load [`PersistedWallet`] with the given `persister`.
223+
/// Load [`PersistedWallet`] with the given [`WalletPersister`].
224224
pub fn load_wallet<P>(
225225
self,
226226
persister: &mut P,
@@ -231,7 +231,7 @@ impl LoadParams {
231231
PersistedWallet::load(persister, self)
232232
}
233233

234-
/// Load [`PersistedWallet`] with the given async `persister`.
234+
/// Load [`PersistedWallet`] with the given [`AsyncWalletPersister`].
235235
pub async fn load_wallet_async<P>(
236236
self,
237237
persister: &mut P,

crates/wallet/src/wallet/persisted.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ pub trait WalletPersister {
3636
/// data, return an empty changeset (using [`ChangeSet::default()`]).
3737
///
3838
/// Error should only occur on database failure. Multiple calls to `initialize` should not
39-
/// error. Calling [`persist`] before calling `initialize` should not error either.
39+
/// error. Calling `initialize` inbetween calls to `persist` should not error.
40+
///
41+
/// Calling [`persist`] before the `persister` is `initialize`d may error. However, some
42+
/// persister implementations may NOT require initialization at all (and not error).
4043
///
4144
/// [`persist`]: WalletPersister::persist
4245
fn initialize(persister: &mut Self) -> Result<ChangeSet, Self::Error>;
@@ -56,7 +59,7 @@ type FutureResult<'a, T, E> = Pin<Box<dyn Future<Output = Result<T, E>> + Send +
5659
/// For a blocking version, use [`WalletPersister`].
5760
///
5861
/// Associated functions of this trait should not be called directly, and the trait is designed so
59-
/// that associated functions are hard to find (since they are not methods!). [`WalletPersister`] is
62+
/// that associated functions are hard to find (since they are not methods!). [`AsyncWalletPersister`] is
6063
/// used by [`PersistedWallet`] (a light wrapper around [`Wallet`]) which enforces some level of
6164
/// safety. Refer to [`PersistedWallet`] for more about the safety checks.
6265
pub trait AsyncWalletPersister {
@@ -66,7 +69,7 @@ pub trait AsyncWalletPersister {
6669
/// Initialize the `persister` and load all data.
6770
///
6871
/// This is called by [`PersistedWallet::create_async`] and [`PersistedWallet::load_async`] to
69-
/// ensure the [`WalletPersister`] is initialized and returns all data in the `persister`.
72+
/// ensure the [`AsyncWalletPersister`] is initialized and returns all data in the `persister`.
7073
///
7174
/// # Implementation Details
7275
///
@@ -76,7 +79,10 @@ pub trait AsyncWalletPersister {
7679
/// data, return an empty changeset (using [`ChangeSet::default()`]).
7780
///
7881
/// Error should only occur on database failure. Multiple calls to `initialize` should not
79-
/// error. Calling [`persist`] before calling `initialize` should not error either.
82+
/// error. Calling `initialize` inbetween calls to `persist` should not error.
83+
///
84+
/// Calling [`persist`] before the `persister` is `initialize`d may error. However, some
85+
/// persister implementations may NOT require initialization at all (and not error).
8086
///
8187
/// [`persist`]: AsyncWalletPersister::persist
8288
fn initialize<'a>(persister: &'a mut Self) -> FutureResult<'a, ChangeSet, Self::Error>
@@ -171,6 +177,8 @@ impl<P: WalletPersister> PersistedWallet<P> {
171177

172178
/// Persist staged changes of wallet into `persister`.
173179
///
180+
/// Returns whether any new changes were persisted.
181+
///
174182
/// If the `persister` errors, the staged changes will not be cleared.
175183
pub fn persist(&mut self, persister: &mut P) -> Result<bool, P::Error> {
176184
match self.inner.staged_mut() {
@@ -186,7 +194,7 @@ impl<P: WalletPersister> PersistedWallet<P> {
186194

187195
/// Methods when `P` is an [`AsyncWalletPersister`].
188196
impl<P: AsyncWalletPersister> PersistedWallet<P> {
189-
/// Create a new [`PersistedWallet`] witht the given async `persister` and `params`.
197+
/// Create a new [`PersistedWallet`] with the given async `persister` and `params`.
190198
pub async fn create_async(
191199
persister: &mut P,
192200
params: CreateParams,
@@ -230,6 +238,8 @@ impl<P: AsyncWalletPersister> PersistedWallet<P> {
230238

231239
/// Persist staged changes of wallet into an async `persister`.
232240
///
241+
/// Returns whether any new changes were persisted.
242+
///
233243
/// If the `persister` errors, the staged changes will not be cleared.
234244
pub async fn persist_async<'a>(&'a mut self, persister: &mut P) -> Result<bool, P::Error> {
235245
match self.inner.staged_mut() {

0 commit comments

Comments
 (0)