corpora-engine 0.1.0

Bus orchestrator and IO edges (parser, fs walk, writer, git oracle) for corpora.
Documentation
//! Terminal-side subscribers: [`Gate`] prints diagnostics as they flow past (the running
//! tally lives in the engine), and [`FailureReporter`] turns `ParseFailed` into a warning
//! so unparsed files are visible rather than silently dropped.

use corpora_core::subscriber::ek;
use corpora_core::{Context, Diagnostic, Event, Interest, Subscriber};

pub struct Gate;

impl Subscriber for Gate {
    fn name(&self) -> &'static str {
        "gate"
    }

    fn interest(&self) -> Interest {
        Interest::only(ek::DIAGNOSTIC)
    }

    fn handle(&mut self, ev: &Event, _cx: &mut Context<'_>) {
        if let Event::Diagnostic(d) = ev {
            eprintln!("{d}");
        }
    }
}

pub struct FailureReporter;

impl Subscriber for FailureReporter {
    fn name(&self) -> &'static str {
        "failures"
    }

    fn interest(&self) -> Interest {
        Interest::only(ek::PARSE_FAILED)
    }

    fn handle(&mut self, ev: &Event, cx: &mut Context<'_>) {
        if let Event::ParseFailed { path, error } = ev {
            cx.error(Diagnostic::warn("PARSE", path, error.0.clone()));
        }
    }
}