Skip to main content

cbor_core/value/
array.rs

1use super::*;
2
3impl<'a> From<Array<'a>> for Value<'a> {
4    fn from(value: Array<'a>) -> Self {
5        Self::Array(value.into_inner())
6    }
7}
8
9impl<'a> From<Vec<Value<'a>>> for Value<'a> {
10    fn from(value: Vec<Value<'a>>) -> Self {
11        Self::Array(value)
12    }
13}
14
15impl<'a, const N: usize> From<[Value<'a>; N]> for Value<'a> {
16    fn from(value: [Value<'a>; N]) -> Self {
17        Self::Array(value.to_vec())
18    }
19}
20
21impl<'a> From<Box<[Value<'a>]>> for Value<'a> {
22    fn from(value: Box<[Value<'a>]>) -> Self {
23        Self::Array(value.into_vec())
24    }
25}
26
27impl<'a> TryFrom<Value<'a>> for Vec<Value<'a>> {
28    type Error = Error;
29    fn try_from(value: Value<'a>) -> Result<Self> {
30        value.into_array()
31    }
32}
33
34impl<'a> TryFrom<&'a Value<'a>> for &'a [Value<'a>] {
35    type Error = Error;
36    fn try_from(value: &'a Value<'a>) -> Result<Self> {
37        value.as_array()
38    }
39}
40
41impl<'a> TryFrom<&'a mut Value<'a>> for &'a mut Vec<Value<'a>> {
42    type Error = Error;
43    fn try_from(value: &'a mut Value<'a>) -> Result<Self> {
44        value.as_array_mut()
45    }
46}
47
48impl<'a> TryFrom<Value<'a>> for Array<'a> {
49    type Error = Error;
50    fn try_from(value: Value<'a>) -> Result<Self> {
51        value.into_array().map(Array::from)
52    }
53}