teo_runtime/value/convert/into/
file.rs

1use teo_result::Error;
2use crate::value::file::File;
3use crate::value::Value;
4
5impl TryFrom<Value> for File {
6
7    type Error = Error;
8
9    fn try_from(value: Value) -> Result<Self, Self::Error> {
10        match value {
11            Value::File(s) => Ok(s),
12            _ => Err(Error::new(format!("Cannot convert {} into File", value.type_hint()))),
13        }
14    }
15}
16
17impl<'a> TryFrom<&'a Value> for File {
18
19    type Error = Error;
20
21    fn try_from(value: &'a Value) -> Result<Self, Self::Error> {
22        match value {
23            Value::File(s) => Ok(s.clone()),
24            _ => Err(Error::new(format!("Cannot convert {} into File", value.type_hint()))),
25        }
26    }
27}
28
29impl<'a> TryFrom<&'a Value> for &'a File {
30
31    type Error = Error;
32
33    fn try_from(value: &'a Value) -> Result<&'a File, Self::Error> {
34        match value {
35            Value::File(s) => Ok(s),
36            _ => Err(Error::new(format!("Cannot convert {} into &File", value.type_hint()))),
37        }
38    }
39}
40
41impl TryFrom<Value> for Option<File> {
42
43    type Error = Error;
44
45    fn try_from(value: Value) -> Result<Self, Self::Error> {
46        match value {
47            Value::Null => Ok(None),
48            Value::File(s) => Ok(Some(s)),
49            _ => Err(Error::new(format!("Cannot convert {} into Option<File>", value.type_hint()))),
50        }
51    }
52}
53
54impl<'a> TryFrom<&'a Value> for Option<&'a File> {
55
56    type Error = Error;
57
58    fn try_from(value: &'a Value) -> Result<Option<&'a File>, Self::Error> {
59        match value {
60            Value::Null => Ok(None),
61            Value::File(s) => Ok(Some(s)),
62            _ => Err(Error::new(format!("Cannot convert {} into Option<&File>", value.type_hint()))),
63        }
64    }
65}
66
67impl<'a> TryFrom<&'a Value> for Option<File> {
68
69    type Error = Error;
70
71    fn try_from(value: &'a Value) -> Result<Option<File>, Self::Error> {
72        match value {
73            Value::Null => Ok(None),
74            Value::File(s) => Ok(Some(s.clone())),
75            _ => Err(Error::new(format!("Cannot convert {} into Option<File>", value.type_hint()))),
76        }
77    }
78}