corpora-core 0.1.0

Core domain types, immutable graph, and event bus for the corpora docs validator.
Documentation
//! The event vocabulary the bus carries. Components communicate only through these.

use std::sync::Arc;

use crate::diagnostic::Diagnostic;
use crate::graph::Graph;
use crate::model::{DocPath, Record};

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Mode {
    Check,
    Report,
    Watch,
}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct RunId(pub u64);

/// A rendered report — pure bytes. The `Writer` persists it; adapters stay IO-free.
#[derive(Clone, Debug)]
pub struct Artifact {
    pub path: DocPath,
    pub bytes: Vec<u8>,
}

#[derive(Clone, Debug, Default)]
pub struct RunSummary {
    pub errors: usize,
    pub warnings: usize,
}

impl RunSummary {
    pub fn exit_code(&self) -> i32 {
        if self.errors > 0 { 1 } else { 0 }
    }
}

#[derive(Clone, Debug)]
pub struct ParseError(pub String);

pub enum Event {
    RunStarted { run: RunId, mode: Mode },
    Discovered(DocPath),
    Changed(DocPath),
    Removed(DocPath),
    /// All sources drained / watch debounce fired — time to build the graph.
    Settled,
    Parsed(Arc<Record>),
    ParseFailed { path: DocPath, error: ParseError },
    GraphBuilt(Arc<Graph>),
    Diagnostic(Diagnostic),
    Report(Artifact),
    RunFinished(RunSummary),
}