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