ailloli_ui_fs/
progress.rs

1//! Provider-neutral progress snapshots for filesystem operations.
2
3use crate::FileOperation;
4
5/// Progress snapshot for one filesystem operation.
6///
7/// Byte counts use bytes, but no invariant enforces `bytes_done <= bytes_total`.
8/// `bytes_total == None` means unknown, while `Some(0)` is a known empty total.
9/// An absent message is distinct from an explicitly empty message.
10///
11/// # Examples
12///
13/// ```
14/// use ailloli_ui_fs::{FileOperation, FileProgress, FileUri};
15/// let progress = FileProgress::new(FileOperation::ReadFile { uri: FileUri::parse("file:///tmp/a")? });
16/// assert_eq!((progress.bytes_done, progress.bytes_total), (0, None));
17/// # Ok::<(), ailloli_ui_fs::FileError>(())
18/// ```
19#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
20pub struct FileProgress {
21    /// Operation whose progress is being reported.
22    pub operation: FileOperation,
23    /// Bytes completed so far; may exceed a separately supplied total.
24    pub bytes_done: u64,
25    /// Known total bytes, or `None` when indeterminate.
26    pub bytes_total: Option<u64>,
27    /// Optional provider-facing status text; `None` means no message.
28    pub message: Option<String>,
29}
30
31impl FileProgress {
32    /// Starts an indeterminate progress snapshot at zero completed bytes.
33    ///
34    /// # Examples
35    ///
36    /// ```
37    /// use ailloli_ui_fs::{FileOperation, FileProgress, FileUri};
38    /// let progress = FileProgress::new(FileOperation::Metadata { uri: FileUri::parse("file:///tmp/a")? });
39    /// assert_eq!(progress.message, None);
40    /// # Ok::<(), ailloli_ui_fs::FileError>(())
41    /// ```
42    pub fn new(operation: FileOperation) -> Self {
43        Self {
44            operation,
45            bytes_done: 0,
46            bytes_total: None,
47            message: None,
48        }
49    }
50}