Skip to content

Commit

Permalink
docs(wallet): fixes/improvements for persisted and params types
Browse files Browse the repository at this point in the history
  • Loading branch information
evanlinjin authored and notmandatory committed Aug 19, 2024
1 parent 9600293 commit 340808e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
8 changes: 4 additions & 4 deletions crates/wallet/src/wallet/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl CreateParams {
self
}

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

/// Create [`PersistedWallet`] with the given async `Db`.
/// Create [`PersistedWallet`] with the given [`AsyncWalletPersister`].
pub async fn create_wallet_async<P>(
self,
persister: &mut P,
Expand Down Expand Up @@ -220,7 +220,7 @@ impl LoadParams {
self
}

/// Load [`PersistedWallet`] with the given `persister`.
/// Load [`PersistedWallet`] with the given [`WalletPersister`].
pub fn load_wallet<P>(
self,
persister: &mut P,
Expand All @@ -231,7 +231,7 @@ impl LoadParams {
PersistedWallet::load(persister, self)
}

/// Load [`PersistedWallet`] with the given async `persister`.
/// Load [`PersistedWallet`] with the given [`AsyncWalletPersister`].
pub async fn load_wallet_async<P>(
self,
persister: &mut P,
Expand Down
20 changes: 15 additions & 5 deletions crates/wallet/src/wallet/persisted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ pub trait WalletPersister {
/// data, return an empty changeset (using [`ChangeSet::default()`]).
///
/// Error should only occur on database failure. Multiple calls to `initialize` should not
/// error. Calling [`persist`] before calling `initialize` should not error either.
/// error. Calling `initialize` inbetween calls to `persist` should not error.
///
/// Calling [`persist`] before the `persister` is `initialize`d may error. However, some
/// persister implementations may NOT require initialization at all (and not error).
///
/// [`persist`]: WalletPersister::persist
fn initialize(persister: &mut Self) -> Result<ChangeSet, Self::Error>;
Expand All @@ -56,7 +59,7 @@ type FutureResult<'a, T, E> = Pin<Box<dyn Future<Output = Result<T, E>> + Send +
/// For a blocking version, use [`WalletPersister`].
///
/// Associated functions of this trait should not be called directly, and the trait is designed so
/// that associated functions are hard to find (since they are not methods!). [`WalletPersister`] is
/// that associated functions are hard to find (since they are not methods!). [`AsyncWalletPersister`] is
/// used by [`PersistedWallet`] (a light wrapper around [`Wallet`]) which enforces some level of
/// safety. Refer to [`PersistedWallet`] for more about the safety checks.
pub trait AsyncWalletPersister {
Expand All @@ -66,7 +69,7 @@ pub trait AsyncWalletPersister {
/// Initialize the `persister` and load all data.
///
/// This is called by [`PersistedWallet::create_async`] and [`PersistedWallet::load_async`] to
/// ensure the [`WalletPersister`] is initialized and returns all data in the `persister`.
/// ensure the [`AsyncWalletPersister`] is initialized and returns all data in the `persister`.
///
/// # Implementation Details
///
Expand All @@ -76,7 +79,10 @@ pub trait AsyncWalletPersister {
/// data, return an empty changeset (using [`ChangeSet::default()`]).
///
/// Error should only occur on database failure. Multiple calls to `initialize` should not
/// error. Calling [`persist`] before calling `initialize` should not error either.
/// error. Calling `initialize` inbetween calls to `persist` should not error.
///
/// Calling [`persist`] before the `persister` is `initialize`d may error. However, some
/// persister implementations may NOT require initialization at all (and not error).
///
/// [`persist`]: AsyncWalletPersister::persist
fn initialize<'a>(persister: &'a mut Self) -> FutureResult<'a, ChangeSet, Self::Error>
Expand Down Expand Up @@ -171,6 +177,8 @@ impl<P: WalletPersister> PersistedWallet<P> {

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

/// Methods when `P` is an [`AsyncWalletPersister`].
impl<P: AsyncWalletPersister> PersistedWallet<P> {
/// Create a new [`PersistedWallet`] witht the given async `persister` and `params`.
/// Create a new [`PersistedWallet`] with the given async `persister` and `params`.
pub async fn create_async(
persister: &mut P,
params: CreateParams,
Expand Down Expand Up @@ -230,6 +238,8 @@ impl<P: AsyncWalletPersister> PersistedWallet<P> {

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

0 comments on commit 340808e

Please sign in to comment.