zonfig 0.1.0

A small dynamic configuration loader with file watching and hot reload support.
Documentation
use std::path::PathBuf;

/// Convenient result type used by `zonfig`.
pub type Result<T> = std::result::Result<T, Error>;

/// Errors returned by configuration loading and watching.
#[derive(Debug, thiserror::Error)]
pub enum Error {
    /// A configuration file could not be read.
    #[error("failed to read config file `{path}`")]
    Read {
        /// Path that failed to read.
        path: PathBuf,
        /// Underlying I/O error.
        #[source]
        source: std::io::Error,
    },

    /// A relative path could not be resolved against the current directory.
    #[error("failed to resolve config path `{path}`")]
    ResolvePath {
        /// Path that failed to resolve.
        path: PathBuf,
        /// Underlying I/O error.
        #[source]
        source: std::io::Error,
    },

    /// The file extension is not one of the supported formats.
    #[error("unsupported config format for `{path}`")]
    UnknownFormat {
        /// Path whose extension could not be mapped to a format.
        path: PathBuf,
    },

    /// File contents could not be parsed as the selected format.
    #[error("failed to parse `{path}` as {format}")]
    Parse {
        /// Path that failed to parse.
        path: PathBuf,
        /// Format used for parsing.
        format: &'static str,
        /// Underlying parser error.
        #[source]
        source: Box<dyn std::error::Error + Send + Sync>,
    },

    /// The file watcher could not be created or updated.
    #[error("failed to watch config file `{path}`")]
    Watch {
        /// Path that failed to watch.
        path: PathBuf,
        /// Underlying watcher error.
        #[source]
        source: notify::Error,
    },

    /// The update channel was closed before another configuration arrived.
    #[error("config watcher stopped")]
    WatchClosed,
}