teo_runtime/value/convert/into/
sort.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
26
27
28
29
30
31
use crate::value::Value;
use teo_result::Error;
use crate::sort::Sort;

impl TryFrom<&Value> for Sort {

    type Error = Error;

    fn try_from(value: &Value) -> Result<Self, Self::Error> {
        let enum_variant: &str = value.try_into()?;
        Ok(match enum_variant {
            "asc" => Sort::Asc,
            "desc" => Sort::Desc,
            _ => unreachable!(),
        })
    }
}

impl TryFrom<Value> for Sort {

    type Error = Error;

    fn try_from(value: Value) -> Result<Self, Self::Error> {
        let enum_variant: &str = value.as_ref().try_into()?;
        Ok(match enum_variant {
            "asc" => Sort::Asc,
            "desc" => Sort::Desc,
            _ => unreachable!(),
        })
    }
}