1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//! Module: progress
//!
//! Responsibility: define process-agnostic query progress events.
//! Does not own: terminal detection, stderr output, or command presentation.
//! Boundary: lets host operations report progress without choosing an output sink.
use std::path::PathBuf;
///
/// QueryProgressEvent
///
/// Structured progress emitted by host-backed query and refresh operations.
///
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum QueryProgressEvent {
/// A cache-backed read is about to refresh from a live endpoint.
CacheRefresh {
/// Human-readable cache component name.
component: String,
/// Cache path that will receive the validated replacement.
path: PathBuf,
/// Explicit live endpoint used to create the cache.
source_endpoint: String,
},
/// Progress from a complete paged snapshot refresh.
PagedRefresh {
/// Human-readable progress text owned by the refresh family.
text: String,
/// Current lifecycle state for the progress message.
state: QueryProgressState,
},
}
///
/// QueryProgressState
///
/// Lifecycle state attached to a paged refresh progress message.
///
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum QueryProgressState {
/// The refresh is still fetching or persisting pages.
Running,
/// The complete snapshot was fetched successfully.
Complete,
/// A source or persistence operation failed.
Failed,
/// A configured page limit stopped the refresh before completion.
Stopped,
/// Paging stopped making forward progress before completion.
Stalled,
}
///
/// QueryProgress
///
/// Process-agnostic sink for structured host-operation progress.
///
pub trait QueryProgress {
/// Receive one progress event.
fn report(&mut self, event: QueryProgressEvent);
}
impl<Reporter> QueryProgress for Reporter
where
Reporter: FnMut(QueryProgressEvent),
{
fn report(&mut self, event: QueryProgressEvent) {
self(event);
}
}
///
/// IgnoreQueryProgress
///
/// No-op progress sink used by silent library entry points.
///
pub struct IgnoreQueryProgress;
impl QueryProgress for IgnoreQueryProgress {
fn report(&mut self, _event: QueryProgressEvent) {}
}