cbor_core/value/
simple_value.rs1use super::*;
2
3impl From<SimpleValue> for Value {
4 fn from(value: SimpleValue) -> Self {
5 Self::SimpleValue(value)
6 }
7}
8
9impl From<bool> for Value {
10 fn from(value: bool) -> Self {
11 Self::SimpleValue(SimpleValue::from_bool(value))
12 }
13}
14
15impl TryFrom<Value> for bool {
16 type Error = Error;
17 fn try_from(value: Value) -> Result<Self> {
18 value.to_bool()
19 }
20}
21
22impl TryFrom<&Value> for bool {
23 type Error = Error;
24 fn try_from(value: &Value) -> Result<Self> {
25 value.to_bool()
26 }
27}
28
29impl TryFrom<Value> for SimpleValue {
30 type Error = Error;
31 fn try_from(value: Value) -> Result<Self> {
32 match value {
33 Value::SimpleValue(sv) => Ok(sv),
34 _ => Err(Error::IncompatibleType(value.data_type())),
35 }
36 }
37}
38
39impl TryFrom<&Value> for SimpleValue {
40 type Error = Error;
41 fn try_from(value: &Value) -> Result<Self> {
42 match value {
43 Value::SimpleValue(sv) => Ok(*sv),
44 _ => Err(Error::IncompatibleType(value.data_type())),
45 }
46 }
47}