1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use teo_result::Error;
use crate::handler::handler::Method;
use crate::interface_enum_variant::InterfaceEnumVariant;
use crate::object::Object;

impl TryFrom<&Object> for Method {

    type Error = Error;

    fn try_from(value: &Object) -> std::result::Result<Self, Self::Error> {
        let enum_variant: InterfaceEnumVariant = value.try_into()?;
        Ok(match enum_variant.value.as_str() {
            "post" => Method::Post,
            "get" => Method::Get,
            "patch" => Method::Patch,
            "put" => Method::Put,
            "delete" => Method::Delete,
            _ => unreachable!(),
        })
    }
}