Skip to main content

MtgaEventStream

Struct MtgaEventStream 

Source
pub struct MtgaEventStream { /* private fields */ }
Expand description

Handle for a running MTG Arena event stream.

Created by MtgaEventStream::start, which opens the log file, wires together the tailer, router, and event bus, and spawns a background task on the caller’s Tokio runtime. The returned Subscriber receives typed GameEvent values as they are parsed.

Call shutdown to stop the background task and clean up resources. Dropping the MtgaEventStream without calling shutdown is safe – the background task will stop when the EventBus is dropped and the entry channel closes.

§Runtime requirement

MtgaEventStream does not create its own Tokio runtime. It must be used from within an active Tokio context (e.g., inside #[tokio::main] or #[tokio::test]).

Implementations§

Source§

impl MtgaEventStream

Source

pub async fn start(log_path: &Path) -> Result<(Self, Subscriber), StreamError>

Starts streaming events from the given log file path.

Opens the log file for tailing from the beginning (catch-up mode), creates an event bus and router, and spawns a background task that:

  1. Polls the file tailer for new log entries
  2. Routes each entry through the parser dispatch chain
  3. Sends recognized events to the event bus

Returns a tuple of (MtgaEventStream, Subscriber). The Subscriber receives cloned GameEvent values. Call shutdown on the MtgaEventStream to stop the background task.

§Errors

Returns StreamError::Tailer if the log file cannot be opened.

Source

pub async fn start_once( log_path: &Path, ) -> Result<(Self, Subscriber), StreamError>

Starts a one-shot event stream that reads an entire log file and exits.

Opens the file via FileTailer::open_from_start, reads all entries, routes them through the parser dispatch chain, and sends recognized events to the event bus. The pipeline stops automatically at EOF rather than polling indefinitely.

This is useful for batch processing complete log files (smoke tests, replay analysis, importing Player-prev.log).

Returns a tuple of (MtgaEventStream, Subscriber). The Subscriber will receive None once all events have been delivered and the pipeline finishes. Calling shutdown on a one-shot stream is a no-op – the pipeline exits at EOF on its own.

§Errors

Returns StreamError::Tailer if the log file cannot be opened.

Source

pub fn shutdown(&self)

Signals the background pipeline to stop.

The tailer flushes any remaining buffered entries before exiting. The Subscriber will receive None once all buffered events have been delivered and the event bus is dropped.

Trait Implementations§

Source§

impl Debug for MtgaEventStream

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.