stawege-html-plugin 0.1.2

HTML template engine plugin for Stawege.
Documentation
use core::error::Error;
use std::path::PathBuf;

#[derive(Debug)]
pub enum HtmlError {
    MissingSourcePath,
    MissingOutputPath,
    NotValidUtf8Encoding,

    MissingClosingTag { tag: String },
    MissingOpeningTag { tag: String },
    FileNotFound { path: PathBuf },
    Other { message: String },
}

// --------------------------
// Error trait implementation
// --------------------------

impl Error for HtmlError {}

// ----------------------------
// Display trait implementation
// ----------------------------

impl core::fmt::Display for HtmlError {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        use HtmlError as E;
        match self {
            E::MissingSourcePath => write!(f, "Missing source_root_path"),
            E::MissingOutputPath => write!(f, "Missing output_root_path"),
            E::NotValidUtf8Encoding => write!(f, "Non valid UTF8 encoding"),
            E::MissingOpeningTag { tag } => write!(f, "Missing opening tag for </{tag}>"),
            E::MissingClosingTag { tag } => write!(f, "Missing closing tag for <{tag}>"),
            E::FileNotFound { path } => write!(f, "File not found: {path:?}"),
            E::Other { message } => write!(f, "{message}"),
        }
    }
}

// -----------------------------
// TryFrom trait implementations
// -----------------------------

impl TryFrom<std::io::Error> for HtmlError {
    type Error = ();

    fn try_from(_value: std::io::Error) -> Result<Self, Self::Error> {
        Err(())
    }
}