1use std::{
2 borrow::Cow,
3 ffi::OsStr,
4 fmt::{Debug, Display, Formatter},
5 ops::Deref,
6 path::Path,
7};
8
9use bstr::{BStr, BString, ByteSlice};
10
11use crate::{borrow::BorrowedInterned, interned::Interned};
12
13impl BorrowedInterned {
14 pub fn as_bstr(&self) -> &BStr {
15 BStr::new(self.deref())
16 }
17
18 pub fn as_path(&self) -> Cow<'_, Path> {
19 self.as_bstr().to_path_lossy()
20 }
21
22 pub fn as_os_str(&self) -> Cow<'_, OsStr> {
23 self.as_bstr().to_os_str_lossy()
24 }
25
26 pub fn as_str(&self) -> Cow<'_, str> {
27 self.as_bstr().to_str_lossy()
28 }
29}
30
31impl Display for Interned {
32 fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
33 Display::fmt(self as &BorrowedInterned, f)
34 }
35}
36
37impl Display for BorrowedInterned {
38 fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
39 Display::fmt(self.as_bstr(), f)
40 }
41}
42
43impl Debug for Interned {
44 fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
45 Debug::fmt(self as &BorrowedInterned, f)
46 }
47}
48
49impl Debug for BorrowedInterned {
50 fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
51 Debug::fmt(self.as_bstr(), f)
52 }
53}
54
55impl From<&BStr> for Interned {
56 fn from(value: &BStr) -> Self {
57 Self::new(value.as_ref())
58 }
59}
60
61impl From<BString> for Interned {
62 fn from(value: BString) -> Self {
63 value.as_bstr().into()
64 }
65}