Skip to main content

weavatrix_scan/
scan_stream.rs

1use crate::report::{
2    IgnoreSourceEvidence, ScanCacheStats, ScanTermination, ScanWarning, ScannedFile, SkippedEntry,
3};
4use std::path::PathBuf;
5
6/// Controls deterministic file emission from [`crate::Scanner::scan_into`].
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum ScanSinkControl {
9    Continue,
10    Stop,
11}
12
13/// Synchronous consumer for selected scan entries.
14///
15/// The scanner does not request the next item until this method returns, which
16/// gives consumers natural backpressure without an unbounded channel.
17pub trait ScanSink {
18    fn on_file(&mut self, file: &ScannedFile) -> ScanSinkControl;
19}
20
21impl<F> ScanSink for F
22where
23    F: FnMut(&ScannedFile) -> ScanSinkControl,
24{
25    fn on_file(&mut self, file: &ScannedFile) -> ScanSinkControl {
26        self(file)
27    }
28}
29
30/// Summary of deterministic, backpressured scan emission.
31///
32/// Selected file records are owned by the sink and are intentionally not
33/// retained here.
34#[derive(Debug)]
35pub struct ScanStreamReport {
36    pub root: PathBuf,
37    pub selected: u64,
38    pub emitted: u64,
39    pub stopped: bool,
40    pub skipped: Vec<SkippedEntry>,
41    pub warnings: Vec<ScanWarning>,
42    pub ignore_sources: Vec<IgnoreSourceEvidence>,
43    pub revision: String,
44    pub complete: bool,
45    pub termination: Option<ScanTermination>,
46    pub portable: bool,
47    pub cache: ScanCacheStats,
48}