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