clientix_core/core/
headers.rs1pub mod content_type {
2 use reqwest::header::HeaderValue;
3
4 #[derive(Debug, Clone, Copy)]
5 pub enum ContentType {
6 ApplicationJson,
7 ApplicationXml,
8 ApplicationXWwwFormUrlEncoded,
9 TextHtml
10 }
11
12 impl TryFrom<String> for ContentType {
13 type Error = ();
14
15 fn try_from(value: String) -> Result<Self, Self::Error> {
16 match value.as_str() {
17 "application/json" => Ok(ContentType::ApplicationJson),
18 "application/xml" => Ok(ContentType::ApplicationXml),
19 "application/x-www-form-urlencoded" => Ok(ContentType::ApplicationXWwwFormUrlEncoded),
20 "text/html" => Ok(ContentType::TextHtml),
21 _ => Err(())
22 }
23 }
24 }
25
26 impl From<ContentType> for String {
27 fn from(value: ContentType) -> String {
28 match value {
29 ContentType::ApplicationJson => "application/json".to_string(),
30 ContentType::ApplicationXml => "application/xml".to_string(),
31 ContentType::ApplicationXWwwFormUrlEncoded => "application/x-www-form-urlencoded".to_string(),
32 ContentType::TextHtml => "text/html".to_string(),
33 }
34 }
35 }
36
37 impl TryFrom<ContentType> for HeaderValue {
38
39 type Error = http::header::InvalidHeaderValue;
40
41 fn try_from(value: ContentType) -> Result<Self, Self::Error> {
42 let string: String = value.into();
43 HeaderValue::from_str(string.as_str())
44 }
45 }
46
47}