Skip to content

Commit

Permalink
Emit events with a mutable ref to an impl
Browse files Browse the repository at this point in the history
  • Loading branch information
sug0 committed May 18, 2024
1 parent 4ed6229 commit 294329c
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions crates/events/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,38 @@ impl EmitEvents for Vec<Event> {
#[inline]
fn emit<E>(&mut self, event: E)
where
E: Into<Event>,
E: EventToEmit,
{
self.push(event.into());
}

/// Emit a batch of [events](Event).
fn emit_many<B, E>(&mut self, event_batch: B)
where
B: IntoIterator<Item = E>,
E: Into<Event>,
E: EventToEmit,
{
self.extend(event_batch.into_iter().map(Into::into));
}
}

impl<EE: EmitEvents> EmitEvents for &mut EE {
#[inline]
fn emit<E>(&mut self, event: E)
where
E: EventToEmit,
{
(*self).emit(event);
}

fn emit_many<B, E>(&mut self, event_batch: B)
where
B: IntoIterator<Item = E>,
E: EventToEmit,
{
(*self).emit_many(event_batch);
}
}

/// Indicates if an event is emitted do to
/// an individual Tx or the nature of a finalized block
#[derive(
Expand Down

0 comments on commit 294329c

Please sign in to comment.