kxio 3.0.0

Provides injectable Filesystem and Network resources to make code more testable
Documentation
//
use std::path::PathBuf;

/// Represents a error accessing the file system.
///
/// Any failure is related to `std::io`, a Path Traversal
/// (i.e. trying to escape the base of the `FileSystem`),
/// or attempting to use a file as a directory or /vise versa/.
#[derive(Debug, derive_more::Display)]
pub enum Error {
    Io(std::io::Error),

    IoString(String),

    #[display("Path access attempted outside of base ({base:?}): {path:?}")]
    PathTraversal {
        base: PathBuf,
        path: PathBuf,
    },

    #[display("Path must be a directory: {path:?}")]
    NotADirectory {
        path: PathBuf,
    },

    #[display("Path must be a file: {path:?}")]
    NotAFile {
        path: PathBuf,
    },
}
impl std::error::Error for Error {}
impl Clone for Error {
    fn clone(&self) -> Self {
        match self {
            Error::Io(err) => Error::IoString(err.to_string()),
            Error::IoString(err) => Error::IoString(err.clone()),
            Error::PathTraversal { base, path } => Error::PathTraversal {
                base: base.clone(),
                path: path.clone(),
            },
            Error::NotADirectory { path } => Error::NotADirectory { path: path.clone() },
            Error::NotAFile { path } => Error::NotAFile { path: path.clone() },
        }
    }
}

/// Represents a success or a failure.
///
/// Any failure is related to `std::io`, a Path Traversal
/// (i.e. trying to escape the base of the `FileSystem`),
/// or attempting to use a file as a directory or /vise versa/.
pub type Result<T> = core::result::Result<T, Error>;