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 GET: &str = "GET";
const POST: &str = "POST";
const PATCH: &str = "PATCH";
const PUT: &str = "PUT";
const DELETE: &str = "DELETE";
const HEAD: &str = "HEAD";
const OPTIONS: &str = "OPTIONS";
const CONNECT: &str = "CONNECT";
const TRACE: &str = "TRACE";

#[derive(Debug, Clone, Copy)]
pub enum HttpRequestMethod {
    Get,
    Post,
    Patch,
    Put,
    Delete,
    Head,
    Options,
    Connect,
    Trace,
}

impl ToString for HttpRequestMethod {
    fn to_string(&self) -> String {
        let result = match self {
            Self::Get => GET,
            Self::Post => POST,
            Self::Put => PUT,
            Self::Patch => PATCH,
            Self::Delete => DELETE,
            Self::Head => HEAD,
            Self::Options => OPTIONS,
            Self::Connect => CONNECT,
            Self::Trace => TRACE,
        };
        result.to_string()
    }
}

impl FromStr for HttpRequestMethod {
    type Err = HttpError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let result = match s {
            GET => Self::Get,
            POST => Self::Post,
            PUT => Self::Put,
            PATCH => Self::Patch,
            DELETE => Self::Delete,
            HEAD => Self::Head,
            OPTIONS => Self::Options,
            CONNECT => Self::Connect,
            TRACE => Self::Trace,
            _ => return Err(HttpErrorKind::Parse.into()),
        };
        Ok(result)
    }
}