Skip to content

Commit

Permalink
chore: minor cleanup (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
hseeberger authored Apr 10, 2024
1 parent 9672c1b commit 8202bc0
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions eventsourced/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ type BoxedAny = Box<dyn Any + Send>;
type BoxedMsg<E> = (BoxedCmd<E>, oneshot::Sender<Result<BoxedAny, BoxedAny>>);

/// State and event handling for an [EventSourcedEntity].
pub trait EventSourced {
pub trait EventSourced
where
Self: Send + Sync + Sized + 'static,
{
/// The Id type.
type Id: Debug + Clone + Send;

Expand Down Expand Up @@ -100,7 +103,7 @@ where

/// The command handler, taking this command, and references to the ID and the state of
/// the event sourced entity, either rejecting this command via [CmdEffect::reject] or returning
/// an event using [CmdEffect::emit_and_reply] (or [CmdEffect::emit] in case Reply = ())).
/// an event using [CmdEffect::emit_and_reply] (or [CmdEffect::emit] in case `Reply = ()`).
fn handle_cmd(self, id: &E::Id, state: &E) -> CmdEffect<E, Self::Reply, Self::Error>;
}

Expand Down Expand Up @@ -156,7 +159,7 @@ where

impl<E> EntityRef<E>
where
E: EventSourced + 'static,
E: EventSourced,
{
/// The ID of the represented [EventSourcedEntity].
pub fn id(&self) -> &E::Id {
Expand Down Expand Up @@ -190,7 +193,7 @@ where
/// Extension methods for [EventSourced] entities.
pub trait EventSourcedExt
where
Self: EventSourced + Sized,
Self: EventSourced,
{
/// Create a new [EventSourcedEntity] for this [EventSourced] implementation.
fn entity(self) -> EventSourcedEntity<Self> {
Expand All @@ -208,7 +211,7 @@ where

impl<E> EventSourcedEntity<E>
where
E: EventSourced + Debug + Send + Sync + 'static,
E: EventSourced,
{
/// Spawn this [EventSourcedEntity] with the given ID, settings, event log, snapshot store and
/// `Binarize` functions.
Expand All @@ -233,7 +236,7 @@ where
.await
.map_err(|error| SpawnError::LoadSnapshot(error.into()))?
.map(|Snapshot { seq_no, state }| {
debug!(?id, seq_no, ?state, "restored snapshot");
debug!(?id, seq_no, "restored snapshot");
(seq_no, state)
})
.unzip();
Expand Down Expand Up @@ -275,7 +278,7 @@ where
.try_fold(state, |state, (_, evt)| ok(state.handle_evt(evt)))
.await?;

debug!(?id, state = ?state, "replayed evts");
debug!(?id, "replayed evts");
}

// Spawn handler loop.
Expand Down Expand Up @@ -400,7 +403,7 @@ where
impl<C, E, Reply, Error> ErasedCmd<E> for C
where
C: Cmd<E, Reply = Reply, Error = Error>,
E: EventSourced + 'static,
E: EventSourced,
Reply: Send + 'static,
Error: Send + 'static,
{
Expand Down Expand Up @@ -532,8 +535,6 @@ mod tests {
)
.await?;

assert!(logs_contain("state=Counter(42)"));

let reply = entity.handle_cmd(IncreaseCounter(1)).await?;
assert_matches!(reply, Ok(43));
let reply = entity.handle_cmd(DecreaseCounter(100)).await?;
Expand Down

0 comments on commit 8202bc0

Please sign in to comment.