Skip to main content

corpora_core/
event.rs

1//! The event vocabulary the bus carries. Components communicate only through these.
2
3use std::sync::Arc;
4
5use crate::diagnostic::Diagnostic;
6use crate::graph::Graph;
7use crate::model::{DocPath, Record};
8
9#[derive(Clone, Copy, Debug, PartialEq, Eq)]
10pub enum Mode {
11    Check,
12    Report,
13    Watch,
14}
15
16#[derive(Clone, Copy, Debug, PartialEq, Eq)]
17pub struct RunId(pub u64);
18
19/// A rendered report — pure bytes. The `Writer` persists it; adapters stay IO-free.
20#[derive(Clone, Debug)]
21pub struct Artifact {
22    pub path: DocPath,
23    pub bytes: Vec<u8>,
24}
25
26#[derive(Clone, Debug, Default)]
27pub struct RunSummary {
28    pub errors: usize,
29    pub warnings: usize,
30}
31
32impl RunSummary {
33    pub fn exit_code(&self) -> i32 {
34        if self.errors > 0 { 1 } else { 0 }
35    }
36}
37
38#[derive(Clone, Debug)]
39pub struct ParseError(pub String);
40
41pub enum Event {
42    RunStarted { run: RunId, mode: Mode },
43    Discovered(DocPath),
44    Changed(DocPath),
45    Removed(DocPath),
46    /// All sources drained / watch debounce fired — time to build the graph.
47    Settled,
48    Parsed(Arc<Record>),
49    ParseFailed { path: DocPath, error: ParseError },
50    GraphBuilt(Arc<Graph>),
51    Diagnostic(Diagnostic),
52    Report(Artifact),
53    RunFinished(RunSummary),
54}