rusync/
progress.rs

1use crate::fsops::SyncOutcome;
2use crate::sync::Stats;
3
4#[doc(hidden)]
5pub enum ProgressMessage {
6    DoneSyncing(SyncOutcome),
7    StartSync(String),
8    Todo {
9        num_files: u64,
10        total_size: usize,
11    },
12    Syncing {
13        description: String,
14        size: usize,
15        done: usize,
16    },
17    SyncError {
18        entry: String,
19        details: String,
20    },
21}
22
23pub struct Progress {
24    /// Name of the file being transferred
25    pub current_file: String,
26    /// Number of bytes transfered for the current file
27    pub file_done: usize,
28    /// Size of the current file (in bytes)
29    pub file_size: usize,
30    /// Number of bytes transfered since the start
31    pub total_done: usize,
32    /// Estimated total size of the transfer (this may change during transfer)
33    pub total_size: usize,
34    /// Index of the current file in the list of all files to transfer
35    pub index: usize,
36    /// Total number of files to transfer
37    pub num_files: usize,
38    /// Estimated time remaining for the transfer, in seconds
39    pub eta: usize,
40}
41
42/// Trait for implementing rusync progress details
43pub trait ProgressInfo {
44    /// A new transfer has begun from the `source` directory to the `destination`
45    /// directory
46    #[allow(unused_variables)]
47    fn start(&mut self, source: &str, destination: &str) {}
48
49    /// A new file named `name` is being transfered
50    #[allow(unused_variables)]
51    fn new_file(&mut self, name: &str) {}
52
53    /// The file transfer is done
54    #[allow(unused_variables)]
55    fn done_syncing(&mut self) {}
56
57    /// Callback for the detailed progress
58    #[allow(unused_variables)]
59    fn progress(&mut self, progress: &Progress) {}
60
61    /// The transfer between `source` and `destination` is done. Details
62    /// of the transfer in the Stats struct
63    #[allow(unused_variables)]
64    fn end(&mut self, stats: &Stats) {}
65
66    /// The entry could not be synced
67    #[allow(unused_variables)]
68    fn error(&mut self, entry: &str, details: &str) {}
69}