1use std::{ffi::OsStr, ops::Deref, path::Path};
2
3use crate::JustString;
4
5impl JustString<'_> {}
6
7impl AsRef<[u8]> for JustString<'_> {
8 fn as_ref(&self) -> &[u8] {
9 match self {
10 Self::RefStr(s) => s.as_ref(),
11 Self::CowStr(s) => s.as_ref().as_ref(),
12 Self::RefString(s) => s.as_ref(),
13 Self::String(s) => s.as_ref(),
14 Self::BoxStr(s) => s.as_ref().as_bytes(),
15 }
16 }
17}
18
19impl AsRef<OsStr> for JustString<'_> {
20 fn as_ref(&self) -> &OsStr {
21 match self {
22 Self::RefStr(s) => s.as_ref(),
23 Self::CowStr(s) => s.as_ref().as_ref(),
24 Self::RefString(s) => s.as_ref(),
25 Self::String(s) => s.as_ref(),
26 Self::BoxStr(s) => s.as_ref().as_ref(),
27 }
28 }
29}
30
31impl AsRef<Path> for JustString<'_> {
32 fn as_ref(&self) -> &Path {
33 match self {
34 Self::RefStr(s) => s.as_ref(),
35 Self::CowStr(s) => s.as_ref().as_ref(),
36 Self::RefString(s) => s.as_ref(),
37 Self::String(s) => s.as_ref(),
38 Self::BoxStr(s) => s.as_ref().as_ref(),
39 }
40 }
41}
42
43impl AsRef<str> for JustString<'_> {
44 fn as_ref(&self) -> &str {
45 match self {
46 Self::RefStr(s) => s,
47 Self::CowStr(s) => s.as_ref(),
48 Self::RefString(s) => s.as_ref(),
49 Self::String(s) => s.as_ref(),
50 Self::BoxStr(s) => s.as_ref(),
51 }
52 }
53}
54
55impl Deref for JustString<'_> {
56 type Target = str;
57
58 fn deref(&self) -> &Self::Target {
59 match self {
60 Self::RefStr(s) => s,
61 Self::CowStr(s) => s,
62 Self::RefString(s) => s,
63 Self::String(s) => s,
64 Self::BoxStr(s) => s,
65 }
66 }
67}