synchronizer 0.1.1

Little daemon service to synchronize all your containers across devices - Keep Your Cluster in Harmony
Documentation
use serde::{Deserialize, Serialize};
use std::{fmt::Debug, net::Ipv4Addr};

use crate::error::SyncError;
#[derive(Serialize, Deserialize)]
pub enum Backend {
    /// Podman
    Podman,
    /// Docker
    Docker,
}
impl Debug for Backend {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Backend::Podman => write!(f, "podman"),
            Backend::Docker => write!(f, "docker"),
        }
    }
}
#[derive(Serialize, Deserialize)]
pub struct Synchronizer {
    /// Hosts to synchronize the containers from and to.
    ///
    /// **First host** in the array is the host to synchronize the setting file from
    /// > Make sure to set up SSH keys before doing any of this, since this is meant to run as background service.
    /// > Also, make sure to set up load balancing before using this.
    pub hosts: Vec<(String, String)>,
    /// Backend to run the containers from
    pub backend: Backend,
    /// If not specified, then the default will be your Docker Compose file in your home directory
    pub file: Option<String>,
}
impl Synchronizer {
    pub fn new() -> Self {
        Self {
            hosts: vec![],
            backend: Backend::Docker,
            file: None,
        }
    }
}

pub fn ip(addr: &str) -> Result<Ipv4Addr, SyncError> {
    let addr_parts: Vec<_> = addr.split('.').collect();
    if addr_parts.len() != 4 {
        return Err(SyncError::InvalidIPv4);
    }
    let addr: Result<Vec<u8>, _> = addr_parts.iter().map(|s| s.parse::<u8>()).collect();
    let addr = addr.map_err(|_| SyncError::InvalidIPv4)?;

    Ok(Ipv4Addr::new(addr[0], addr[1], addr[2], addr[3]))
}