wkhtmlapp 1.2.0

Convert html to pdf or image
Documentation
use crate::{ImgApp, PdfApp};

/// Input source for a render: a local file path, a URL, or raw HTML
/// (piped through stdin).
#[derive(Debug, Clone)]
pub enum WkhtmlInput<'a> {
    File(&'a str),
    Url(&'a str),
    Html(&'a str),
}

/// Library error type. `ServiceErr` covers setup/configuration problems,
/// `RenderingErr` covers failures while running the wkhtmltox binary.
#[derive(Debug, Clone)]
pub enum WkhtmlError {
    ServiceErr(String),
    RenderingErr(String),
}

impl std::fmt::Display for WkhtmlError {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        match self {
            WkhtmlError::ServiceErr(msg) => write!(f, "Service error: {}", msg),
            WkhtmlError::RenderingErr(msg) => write!(f, "Rendering error: {}", msg),
        }
    }
}

impl std::error::Error for WkhtmlError {}

/// Convenience wrapper exposing both converters at once.
#[derive(Debug, Clone)]
pub struct App {
    pub pdf_app: PdfApp,
    pub img_app: ImgApp,
}

impl App {
    pub fn new() -> Result<Self, WkhtmlError> {
        Ok(Self {
            pdf_app: PdfApp::new()?,
            img_app: ImgApp::new()?,
        })
    }
}