Skip to main content

rsynko_memory/
observation.rs

1//! The reified download observations and the observation stream carrying them.
2
3use alux_sdk::trait_algebra;
4use derive_new::new;
5use std::path::PathBuf;
6
7/// Defines the first-order observation stream emitted by one download.
8#[trait_algebra(derive(Clone, Debug, PartialEq, Eq))]
9pub trait DownloadObservation {
10    /// Observes non-terminal byte progress.
11    fn progress(&self, progress: DownloadProgress);
12
13    /// Observes terminal download completion or failure.
14    fn terminal(&self, event: DownloadEvent);
15}
16
17/// Denotes one monotonic observation of bytes retrieved for a destination.
18#[derive(Clone, Debug, PartialEq, Eq, new)]
19pub struct DownloadProgress {
20    /// Names the intended final path.
21    pub destination: PathBuf,
22    /// Counts bytes retrieved so far.
23    pub downloaded: u64,
24    /// Denotes the expected complete byte count when known.
25    pub total: Option<u64>,
26}
27
28/// Denotes one terminal download observation.
29#[derive(Clone, Debug, PartialEq, Eq)]
30pub enum DownloadEvent {
31    /// Denotes successful atomic publication.
32    Succeeded {
33        /// Names the published path.
34        destination: PathBuf,
35        /// Counts published bytes.
36        bytes: u64,
37    },
38    /// Denotes failure before publication completed.
39    Failed {
40        /// Names the intended final path.
41        destination: PathBuf,
42        /// Preserves a stable human-readable cause.
43        message: String,
44    },
45}