Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/crates/wasi-http/src/p3/conv.rs
1692 views
1
use crate::p3::bindings::http::types::{ErrorCode, Method, Scheme};
2
use core::convert::Infallible;
3
4
impl From<Infallible> for ErrorCode {
5
fn from(x: Infallible) -> Self {
6
match x {}
7
}
8
}
9
10
impl From<http::Method> for Method {
11
fn from(method: http::Method) -> Self {
12
Self::from(&method)
13
}
14
}
15
16
impl From<&http::Method> for Method {
17
fn from(method: &http::Method) -> Self {
18
if method == http::Method::GET {
19
Self::Get
20
} else if method == http::Method::HEAD {
21
Self::Head
22
} else if method == http::Method::POST {
23
Self::Post
24
} else if method == http::Method::PUT {
25
Self::Put
26
} else if method == http::Method::DELETE {
27
Self::Delete
28
} else if method == http::Method::CONNECT {
29
Self::Connect
30
} else if method == http::Method::OPTIONS {
31
Self::Options
32
} else if method == http::Method::TRACE {
33
Self::Trace
34
} else if method == http::Method::PATCH {
35
Self::Patch
36
} else {
37
Self::Other(method.as_str().into())
38
}
39
}
40
}
41
42
impl TryFrom<Method> for http::Method {
43
type Error = http::method::InvalidMethod;
44
45
fn try_from(method: Method) -> Result<Self, Self::Error> {
46
Self::try_from(&method)
47
}
48
}
49
50
impl TryFrom<&Method> for http::Method {
51
type Error = http::method::InvalidMethod;
52
53
fn try_from(method: &Method) -> Result<Self, Self::Error> {
54
match method {
55
Method::Get => Ok(Self::GET),
56
Method::Head => Ok(Self::HEAD),
57
Method::Post => Ok(Self::POST),
58
Method::Put => Ok(Self::PUT),
59
Method::Delete => Ok(Self::DELETE),
60
Method::Connect => Ok(Self::CONNECT),
61
Method::Options => Ok(Self::OPTIONS),
62
Method::Trace => Ok(Self::TRACE),
63
Method::Patch => Ok(Self::PATCH),
64
Method::Other(s) => s.parse(),
65
}
66
}
67
}
68
69
impl From<http::uri::Scheme> for Scheme {
70
fn from(scheme: http::uri::Scheme) -> Self {
71
Self::from(&scheme)
72
}
73
}
74
75
impl From<&http::uri::Scheme> for Scheme {
76
fn from(scheme: &http::uri::Scheme) -> Self {
77
if *scheme == http::uri::Scheme::HTTP {
78
Self::Http
79
} else if *scheme == http::uri::Scheme::HTTPS {
80
Self::Https
81
} else {
82
Self::Other(scheme.as_str().into())
83
}
84
}
85
}
86
87
impl TryFrom<Scheme> for http::uri::Scheme {
88
type Error = http::uri::InvalidUri;
89
90
fn try_from(scheme: Scheme) -> Result<Self, Self::Error> {
91
Self::try_from(&scheme)
92
}
93
}
94
95
impl TryFrom<&Scheme> for http::uri::Scheme {
96
type Error = http::uri::InvalidUri;
97
98
fn try_from(scheme: &Scheme) -> Result<Self, Self::Error> {
99
match scheme {
100
Scheme::Http => Ok(Self::HTTP),
101
Scheme::Https => Ok(Self::HTTPS),
102
Scheme::Other(s) => s.parse(),
103
}
104
}
105
}
106
107