web_archive/
error.rs

1// Copyright 2020 David Young
2//
3// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
4// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5// http://opensource.org/licenses/MIT>, at your option. This file may not be
6// copied, modified, or distributed except according to those terms.
7
8//! Module for the error parsing functionality
9
10use std::string::FromUtf8Error;
11
12/// Error type used by `web_archive` to wrap the errors returned by
13/// operations in this crate or errors from other sources (e.g. URL
14/// parsing or network errors).
15#[derive(Debug)]
16pub enum Error {
17    /// Some kind of parsing error
18    ParseError(String),
19    /// Error fetching a resource
20    ReqwestError(String),
21}
22
23impl From<reqwest::Error> for Error {
24    fn from(e: reqwest::Error) -> Self {
25        Self::ReqwestError(e.to_string())
26    }
27}
28
29impl From<std::io::Error> for Error {
30    fn from(e: std::io::Error) -> Self {
31        Self::ParseError(e.to_string())
32    }
33}
34
35impl From<FromUtf8Error> for Error {
36    fn from(e: FromUtf8Error) -> Self {
37        Self::ParseError(e.to_string())
38    }
39}