sett 0.4.0

Rust port of sett (data compression, encryption and transfer tool).
Documentation
//! Destination types for data packages.
use std::{
    fmt::Debug,
    path::{Path, PathBuf},
};

/// Destination type for data packages.
#[derive(Debug)]
pub enum Destination {
    /// Location in the local filesystem.
    Local(Local),
    /// Standard output.
    Stdout,
    /// Location on a SFTP server.
    Sftp(Sftp),
    /// Location on an S3-compatible object store.
    S3(crate::remote::s3::Location),
}

impl From<Local> for Destination {
    fn from(opts: Local) -> Self {
        Destination::Local(opts)
    }
}

impl From<Sftp> for Destination {
    fn from(sftp: Sftp) -> Self {
        Destination::Sftp(sftp)
    }
}

impl From<crate::remote::s3::Location> for Destination {
    fn from(s3: crate::remote::s3::Location) -> Self {
        Destination::S3(s3)
    }
}

#[derive(Debug, Clone)]
/// Local destination.
pub struct Local {
    /// Path to the directory where the data package will be stored.
    pub(crate) path: PathBuf,
    /// Name of the encrypted data package.
    pub(crate) name: Option<String>,
}

impl Local {
    /// Creates a new local destination.
    ///
    /// `path` must be a directory. If `name` is `None`, a package name will be generated.
    /// If `name` is `Some`, it will be used as the package name.
    pub fn new(
        path: impl Into<PathBuf>,
        name: Option<impl Into<String>>,
    ) -> Result<Self, std::io::Error> {
        Ok(Self {
            path: path.into().canonicalize()?,
            name: name.map(Into::into),
        })
    }

    pub(crate) fn package_name(
        &self,
        timestamp: &chrono::DateTime<chrono::Utc>,
        prefix: Option<&str>,
    ) -> String {
        self.name.as_ref().map_or_else(
            || crate::package::generate_package_name(timestamp, prefix),
            Into::into,
        )
    }
}

/// SFTP destination.
#[derive(Debug)]
pub struct Sftp {
    /// Client object to connect with SFTP server.
    client: crate::remote::sftp::Client,
    /// Path on the remote SFTP host where encrypted files will be stored.
    base_path: PathBuf,
}

impl Sftp {
    /// Creates a new SFTP destination.
    pub fn new(client: crate::remote::sftp::Client, base_path: impl Into<PathBuf>) -> Self {
        Self {
            client,
            base_path: base_path.into(),
        }
    }

    /// Returns the SFTP client.
    pub fn client(&self) -> &crate::remote::sftp::Client {
        &self.client
    }

    /// Returns the base path.
    pub fn base_path(&self) -> &Path {
        &self.base_path
    }
}