teo_runtime/value/convert/into/
sort.rs

1use crate::value::Value;
2use teo_result::Error;
3use crate::sort::Sort;
4
5impl TryFrom<&Value> for Sort {
6
7    type Error = Error;
8
9    fn try_from(value: &Value) -> Result<Self, Self::Error> {
10        let enum_variant: &str = value.try_into()?;
11        Ok(match enum_variant {
12            "asc" => Sort::Asc,
13            "desc" => Sort::Desc,
14            _ => unreachable!(),
15        })
16    }
17}
18
19impl TryFrom<Value> for Sort {
20
21    type Error = Error;
22
23    fn try_from(value: Value) -> Result<Self, Self::Error> {
24        let enum_variant: &str = value.as_ref().try_into()?;
25        Ok(match enum_variant {
26            "asc" => Sort::Asc,
27            "desc" => Sort::Desc,
28            _ => unreachable!(),
29        })
30    }
31}