adblock-list-compiler 0.0.8

CLI tool to compile multiple adblock list sources into a single file
Documentation
mod file;
mod http;

use std::path::PathBuf;

use thiserror::Error;
use url::Url;

use self::{
    file::{FetchFile, FetchFileError},
    http::{FetchHTTPError, FetchHttp},
};

#[derive(Debug)]
pub enum Fetch {
    Http(FetchHttp),
    File(FetchFile),
}

#[derive(Error, Debug)]
pub enum FetchError {
    #[error("HTTPError: {0}")]
    HTTPError(#[from] FetchHTTPError),

    #[error("FileError: {0}")]
    FileError(#[from] FetchFileError),
}

impl Fetch {
    pub async fn fetch(&self) -> Result<String, FetchError> {
        match self {
            Fetch::Http(p) => Ok(p.fetch().await?),
            Fetch::File(p) => Ok(p.fetch().await?),
        }
    }
}

impl From<Url> for Fetch {
    fn from(url: Url) -> Self {
        Self::Http(FetchHttp { url })
    }
}

impl From<PathBuf> for Fetch {
    fn from(path: PathBuf) -> Self {
        Self::File(FetchFile { path })
    }
}