Skip to main content

cbor_core/value/
string.rs

1use std::borrow::Cow;
2
3use crate::{Error, Result, Value};
4
5impl From<char> for Value<'_> {
6    fn from(value: char) -> Self {
7        Self::TextString(value.to_string().into())
8    }
9}
10
11impl<'a> From<&'a str> for Value<'a> {
12    fn from(value: &'a str) -> Self {
13        Self::TextString(value.into())
14    }
15}
16
17impl From<String> for Value<'_> {
18    fn from(value: String) -> Self {
19        Self::TextString(value.into())
20    }
21}
22
23impl<'a> From<&'a String> for Value<'a> {
24    fn from(value: &'a String) -> Self {
25        Self::TextString(value.as_str().into())
26    }
27}
28
29impl From<Box<str>> for Value<'_> {
30    fn from(value: Box<str>) -> Self {
31        Self::TextString(String::from(value).into())
32    }
33}
34
35impl<'a> From<Cow<'a, str>> for Value<'a> {
36    fn from(value: Cow<'a, str>) -> Self {
37        Self::TextString(value)
38    }
39}
40
41impl<'a> TryFrom<Value<'a>> for String {
42    type Error = Error;
43    fn try_from(value: Value<'a>) -> Result<Self> {
44        value.into_string()
45    }
46}
47
48impl<'a> TryFrom<&'a Value<'a>> for &'a str {
49    type Error = Error;
50    fn try_from(value: &'a Value<'a>) -> Result<Self> {
51        value.as_str()
52    }
53}
54
55impl<'a> TryFrom<&'a mut Value<'a>> for &'a mut String {
56    type Error = Error;
57    fn try_from(value: &'a mut Value<'a>) -> Result<Self> {
58        value.as_string_mut()
59    }
60}