remozipsy 0.2.0

Remote Zip Sync - sync remote zip to local fs
Documentation
use core::fmt::Debug;

mod compare;
mod download_unzip_delete;
mod remote;
mod state;

use super::{FileSystem, RemoteZip};
use crate::{
    model::{Config, Progress},
    proto::sync::state::State,
};

/// Main struct to sync remote with local via [`Self::progress`].
#[derive(Debug)]
pub struct Statemachine<R: RemoteZip, F: FileSystem> {
    internal: State<R, F>,
}

impl<R, F> Statemachine<R, F>
where
    R: RemoteZip + Clone + Send + 'static,
    F: FileSystem + Clone + Send + 'static,
{
    pub fn new(remote: R, file_system: F, config: Config) -> Self {
        Self {
            internal: State::ToBeEvaluated(remote, file_system, config),
        }
    }

    /// This is the function that advances this state-machine.
    /// On call it will evaluate a small step towards completion and returns a
    /// progress afterwards.
    ///
    /// Usage: call it in a loop and present status to user.
    pub async fn progress(self) -> Option<(Progress<R::Error, F::Error>, Self)> {
        self.internal
            .progress()
            .await
            .map(|(progress, internal)| (progress, Self { internal }))
    }
}