1use std::{
2 borrow::Cow, convert::Infallible, error::Error, ffi::OsString, ops::Deref, path::PathBuf,
3 rc::Rc, str::FromStr, sync::Arc,
4};
5
6use crate::JustString;
7
8impl<'a> From<&'a JustString<'_>> for Cow<'a, str> {
9 fn from(value: &'a JustString<'_>) -> Self {
10 value.deref().into()
11 }
12}
13
14impl From<JustString<'_>> for Arc<str> {
15 fn from(value: JustString<'_>) -> Self {
16 value.deref().into()
17 }
18}
19
20impl From<JustString<'_>> for Box<dyn Error + '_> {
21 fn from(value: JustString<'_>) -> Self {
22 value.deref().into()
23 }
24}
25
26impl From<JustString<'_>> for Box<dyn Error + Send + Sync + '_> {
27 fn from(value: JustString<'_>) -> Self {
28 value.deref().into()
29 }
30}
31
32impl From<JustString<'_>> for Box<str> {
33 fn from(value: JustString<'_>) -> Self {
34 value.deref().into()
35 }
36}
37
38impl<'a> From<JustString<'a>> for Cow<'a, str> {
39 fn from(value: JustString<'a>) -> Self {
40 match value {
41 JustString::RefStr(s) => s.into(),
42 JustString::CowStr(s) => s,
43 JustString::RefString(s) => s.deref().into(),
44 JustString::String(s) => s.into(),
45 JustString::BoxStr(s) => s.to_string().into(),
46 }
47 }
48}
49
50impl From<JustString<'_>> for OsString {
51 fn from(value: JustString<'_>) -> Self {
52 value.deref().into()
53 }
54}
55
56impl From<JustString<'_>> for PathBuf {
57 fn from(value: JustString<'_>) -> Self {
58 value.deref().into()
59 }
60}
61
62impl From<JustString<'_>> for Rc<str> {
63 fn from(value: JustString<'_>) -> Self {
64 value.deref().into()
65 }
66}
67
68impl From<JustString<'_>> for Vec<u8> {
69 fn from(value: JustString<'_>) -> Self {
70 value.deref().into()
71 }
72}
73
74impl FromStr for JustString<'_> {
75 type Err = Infallible;
76
77 fn from_str(s: &str) -> Result<Self, Self::Err> {
78 Ok(JustString::String(s.to_owned()))
79 }
80}