httpio 0.2.4

A transport-agnostic, async HTTP/1.1 client library for any runtime.
Documentation
use crate::enums::http_error::HttpError;
use std::str::FromStr;

use super::http_error::HttpErrorKind;

const HTTP_10: &str = "HTTP/1.0";
const HTTP_11: &str = "HTTP/1.1";
const HTTP_20: &str = "HTTP/2";

#[derive(Clone, Debug, Copy)]
pub enum HttpVersion {
    Http10,
    Http11,
    Http20,
}

impl ToString for HttpVersion {
    fn to_string(&self) -> String {
        let result = match self {
            Self::Http10 => HTTP_10,
            Self::Http11 => HTTP_11,
            Self::Http20 => HTTP_20,
        };
        result.to_string()
    }
}

impl FromStr for HttpVersion {
    type Err = HttpError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let result = match s {
            HTTP_10 => Self::Http10,
            HTTP_11 => Self::Http11,
            HTTP_20 => Self::Http20,
            _ => return Err(HttpErrorKind::Parse.into()),
        };
        Ok(result)
    }
}