Skip to content

Commit

Permalink
docs and is_some
Browse files Browse the repository at this point in the history
  • Loading branch information
angelo-rendina-prima committed May 7, 2024
1 parent fb1ff8e commit 8ab3e7b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ where
/// Acquires a lock on this aggregate instance, and only then loads it from the event store,
/// by applying previously persisted events onto the aggregate state by order of their sequence number.
///
/// The lock is contained in the returned `AggregateState`, and released when this is dropped.
/// It can also be extracted with the `take_lock` method for more advanced uses.
/// The returned [`LockedLoad`] contains the outcome of the load and is responsible for correctly managing the lock.
pub async fn lock_and_load(
&self,
aggregate_id: impl Into<Uuid> + Send,
Expand Down
9 changes: 9 additions & 0 deletions src/manager/locked_load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ impl<T> LockedLoad<T> {
Self(LockedLoadInner::None { id, lock })
}

/// Checks if the AggregateState was found.
pub fn is_some(&self) -> bool {
let Self(inner) = self;
match inner {
LockedLoadInner::None { .. } => false,
LockedLoadInner::Some(_) => true,
}
}

/// Extracts the contained AggregateState, or panics otherwise.
pub fn unwrap(self) -> AggregateState<T> {
let Self(inner) = self;
Expand Down

0 comments on commit 8ab3e7b

Please sign in to comment.