1use alloc::borrow::Cow;
2use core::str::FromStr;
3use std::{
4 ffi::OsStr,
5 path::{Path, PathBuf},
6};
7
8use crate::inline::{InlineFlexStr, TooLongForInlining, inline_partial_eq_impl};
9
10use flexstr_support::StringToFromBytes;
11
12pub type InlinePath = InlineFlexStr<Path>;
14
15impl<'s> TryFrom<&'s Path> for InlineFlexStr<Path> {
19 type Error = TooLongForInlining;
20
21 #[inline]
22 fn try_from(s: &'s Path) -> Result<Self, Self::Error> {
23 InlineFlexStr::try_from_type(s)
24 }
25}
26
27impl<'s> TryFrom<&'s str> for InlineFlexStr<Path> {
28 type Error = TooLongForInlining;
29
30 #[inline]
31 fn try_from(s: &'s str) -> Result<Self, Self::Error> {
32 InlineFlexStr::try_from_type(Path::new(s))
33 }
34}
35
36impl<'s> TryFrom<&'s OsStr> for InlineFlexStr<Path> {
37 type Error = TooLongForInlining;
38
39 #[inline]
40 fn try_from(s: &'s OsStr) -> Result<Self, Self::Error> {
41 InlineFlexStr::try_from_type(Path::new(s))
42 }
43}
44
45inline_partial_eq_impl!(Path, Path);
48inline_partial_eq_impl!(&Path, Path);
49inline_partial_eq_impl!(PathBuf, Path);
50inline_partial_eq_impl!(Cow<'_, Path>, Path);
51
52impl<S: ?Sized + StringToFromBytes> AsRef<Path> for InlineFlexStr<S>
55where
56 S: AsRef<Path>,
57{
58 fn as_ref(&self) -> &Path {
59 self.as_ref_type().as_ref()
60 }
61}
62
63impl FromStr for InlineFlexStr<Path> {
66 type Err = TooLongForInlining;
67
68 fn from_str(s: &str) -> Result<Self, Self::Err> {
69 InlineFlexStr::try_from_type(Path::new(s))
70 }
71}