Path: blob/main/crates/wasi-http/src/p3/conv.rs
1692 views
use crate::p3::bindings::http::types::{ErrorCode, Method, Scheme};1use core::convert::Infallible;23impl From<Infallible> for ErrorCode {4fn from(x: Infallible) -> Self {5match x {}6}7}89impl From<http::Method> for Method {10fn from(method: http::Method) -> Self {11Self::from(&method)12}13}1415impl From<&http::Method> for Method {16fn from(method: &http::Method) -> Self {17if method == http::Method::GET {18Self::Get19} else if method == http::Method::HEAD {20Self::Head21} else if method == http::Method::POST {22Self::Post23} else if method == http::Method::PUT {24Self::Put25} else if method == http::Method::DELETE {26Self::Delete27} else if method == http::Method::CONNECT {28Self::Connect29} else if method == http::Method::OPTIONS {30Self::Options31} else if method == http::Method::TRACE {32Self::Trace33} else if method == http::Method::PATCH {34Self::Patch35} else {36Self::Other(method.as_str().into())37}38}39}4041impl TryFrom<Method> for http::Method {42type Error = http::method::InvalidMethod;4344fn try_from(method: Method) -> Result<Self, Self::Error> {45Self::try_from(&method)46}47}4849impl TryFrom<&Method> for http::Method {50type Error = http::method::InvalidMethod;5152fn try_from(method: &Method) -> Result<Self, Self::Error> {53match method {54Method::Get => Ok(Self::GET),55Method::Head => Ok(Self::HEAD),56Method::Post => Ok(Self::POST),57Method::Put => Ok(Self::PUT),58Method::Delete => Ok(Self::DELETE),59Method::Connect => Ok(Self::CONNECT),60Method::Options => Ok(Self::OPTIONS),61Method::Trace => Ok(Self::TRACE),62Method::Patch => Ok(Self::PATCH),63Method::Other(s) => s.parse(),64}65}66}6768impl From<http::uri::Scheme> for Scheme {69fn from(scheme: http::uri::Scheme) -> Self {70Self::from(&scheme)71}72}7374impl From<&http::uri::Scheme> for Scheme {75fn from(scheme: &http::uri::Scheme) -> Self {76if *scheme == http::uri::Scheme::HTTP {77Self::Http78} else if *scheme == http::uri::Scheme::HTTPS {79Self::Https80} else {81Self::Other(scheme.as_str().into())82}83}84}8586impl TryFrom<Scheme> for http::uri::Scheme {87type Error = http::uri::InvalidUri;8889fn try_from(scheme: Scheme) -> Result<Self, Self::Error> {90Self::try_from(&scheme)91}92}9394impl TryFrom<&Scheme> for http::uri::Scheme {95type Error = http::uri::InvalidUri;9697fn try_from(scheme: &Scheme) -> Result<Self, Self::Error> {98match scheme {99Scheme::Http => Ok(Self::HTTP),100Scheme::Https => Ok(Self::HTTPS),101Scheme::Other(s) => s.parse(),102}103}104}105106107