Skip to main content

weavatrix_scan/
scan_stream.rs

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