Skip to main content

manasight_parser/
lib.rs

1//! MTG Arena log file parser.
2//!
3//! This library crate reads Arena's `Player.log`, parses raw log entries
4//! into typed game events, and distributes them via an async broadcast
5//! channel. It is designed to run on the caller's Tokio runtime — it does
6//! not initialize its own runtime or logger.
7//!
8//! # Quick start
9//!
10//! ```rust,no_run
11//! use std::path::Path;
12//! use manasight_parser::MtgaEventStream;
13//!
14//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
15//! let (stream, mut subscriber) = MtgaEventStream::start(Path::new("Player.log")).await?;
16//!
17//! while let Some(event) = subscriber.recv().await {
18//!     println!("got event: {event:?}");
19//! }
20//! # Ok(())
21//! # }
22//! ```
23//!
24//! # Architecture
25//!
26//! ```text
27//! Player.log → File Tailer → Entry Buffer → Router → Parsers → Event Bus
28//! ```
29//!
30//! - **`log`** module: file discovery, polling tailer, entry accumulation, timestamps
31//! - **`router`**: dispatches raw entries to the correct category parser
32//! - **`parsers`**: one sub-module per event category
33//! - **`events`**: public event type enums/structs (the parser's output contract)
34//! - **`event_bus`**: `tokio::broadcast` channel for fan-out to subscribers
35//! - **`stream`**: public entry point ([`MtgaEventStream`])
36
37pub mod event_bus;
38pub mod events;
39pub mod log;
40pub mod parsers;
41pub mod router;
42pub mod sanitize;
43pub mod stream;
44pub mod util;
45
46// ---------------------------------------------------------------------------
47// Re-exports — public API surface
48// ---------------------------------------------------------------------------
49
50pub use event_bus::Subscriber;
51pub use events::{
52    ClientActionEvent, DeckCollectionEvent, DetailedLoggingStatusEvent, DraftBotEvent,
53    DraftCompleteEvent, DraftHumanEvent, EventLifecycleEvent, EventMetadata, GameEvent,
54    GameResultEvent, GameStateEvent, InventoryEvent, LogFileRotatedEvent, MatchStateEvent,
55    PerformanceClass, RankEvent, SessionEvent,
56};
57pub use sanitize::scrub_raw_log;
58pub use stream::{MtgaEventStream, StreamError};
59pub use util::{compress_log, content_hash};