remozipsy 0.0.2

zip implementation independent structs and helpers
Documentation
use core::fmt::Debug;

mod compare;
mod download;
mod handle_processor;
mod remote;
mod state;

use super::{FileSystem, RemoteZip};
use crate::{
    model::{Config, Progress},
    proto::sync::{
        download::{DownloadResult, UnzipResult},
        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 `fn` 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 }))
    }
}