1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
use conjure_object::serde::{de, ser}; use std::fmt; use std::str; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum HttpMethod { Get, Post, Put, Delete, } impl HttpMethod { #[doc = r" Returns the string representation of the enum."] #[inline] pub fn as_str(&self) -> &str { match self { HttpMethod::Get => "GET", HttpMethod::Post => "POST", HttpMethod::Put => "PUT", HttpMethod::Delete => "DELETE", } } } impl fmt::Display for HttpMethod { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fmt::Display::fmt(self.as_str(), fmt) } } impl conjure_object::Plain for HttpMethod { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { conjure_object::Plain::fmt(self.as_str(), fmt) } } impl str::FromStr for HttpMethod { type Err = conjure_object::plain::ParseEnumError; #[inline] fn from_str(v: &str) -> Result<HttpMethod, conjure_object::plain::ParseEnumError> { match v { "GET" => Ok(HttpMethod::Get), "POST" => Ok(HttpMethod::Post), "PUT" => Ok(HttpMethod::Put), "DELETE" => Ok(HttpMethod::Delete), _ => Err(conjure_object::plain::ParseEnumError::new()), } } } impl conjure_object::FromPlain for HttpMethod { type Err = conjure_object::plain::ParseEnumError; #[inline] fn from_plain(v: &str) -> Result<HttpMethod, conjure_object::plain::ParseEnumError> { v.parse() } } impl ser::Serialize for HttpMethod { fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error> where S: ser::Serializer, { s.serialize_str(self.as_str()) } } impl<'de> de::Deserialize<'de> for HttpMethod { fn deserialize<D>(d: D) -> Result<HttpMethod, D::Error> where D: de::Deserializer<'de>, { d.deserialize_str(Visitor_) } } struct Visitor_; impl<'de> de::Visitor<'de> for Visitor_ { type Value = HttpMethod; fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fmt.write_str("a string") } fn visit_str<E>(self, v: &str) -> Result<HttpMethod, E> where E: de::Error, { match v.parse() { Ok(e) => Ok(e), Err(_) => Err(de::Error::unknown_variant( v, &["GET", "POST", "PUT", "DELETE"], )), } } }