teo_runtime/value/convert/into/
method.rs

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
use teo_result::Error;
use hyper::Method;
use crate::value::interface_enum_variant::InterfaceEnumVariant;
use crate::value::Value;

impl TryFrom<&Value> for Method {

    type Error = Error;

    fn try_from(value: &Value) -> Result<Self, Self::Error> {
        let interface_enum_variant: InterfaceEnumVariant = value.try_into()?;
        Ok(match interface_enum_variant.value.as_str() {
            "post" => Method::POST,
            "get" => Method::GET,
            "patch" => Method::PATCH,
            "put" => Method::PUT,
            "delete" => Method::DELETE,
            "options" => Method::OPTIONS,
            "head" => Method::HEAD,
            "connect" => Method::CONNECT,
            "trace" => Method::TRACE,
            _ => unreachable!(),
        })
    }
}