proper_path_tools/
try_into_cow_path.rs1mod private
3{
4 use crate::*;
5 use std::
6 {
7 borrow::Cow,
8 io,
9 path::{ Component, Path, PathBuf },
10 };
11 pub trait TryIntoCowPath<'a>
20 {
21 fn try_into_cow_path( self ) -> Result< Cow<'a, Path>, io::Error >;
28 }
29
30 impl<'a> TryIntoCowPath<'a> for &'a str
32 {
33 fn try_into_cow_path( self ) -> Result< Cow<'a, Path>, io::Error >
34 {
35 Ok( Cow::Borrowed( self.as_path() ) )
36 }
37 }
38
39 impl<'a> TryIntoCowPath<'a> for String
41 {
42 fn try_into_cow_path( self ) -> Result< Cow<'a, Path>, io::Error >
43 {
44 Ok( Cow::Owned( PathBuf::from( self ) ) )
45 }
46 }
47
48 impl<'a> TryIntoCowPath<'a> for PathBuf
50 {
51 fn try_into_cow_path( self ) -> Result< Cow<'a, Path>, io::Error >
52 {
53 Ok( Cow::Owned( self ) )
54 }
55 }
56
57 impl<'a> TryIntoCowPath<'a> for &'a Path
59 {
60 fn try_into_cow_path( self ) -> Result< Cow<'a, Path>, io::Error >
61 {
62 Ok( Cow::Borrowed( self ) )
63 }
64 }
65
66 #[cfg( feature = "path_utf8" )]
68 impl< 'a > TryIntoCowPath< 'a > for &'a Utf8Path
69 {
70 fn try_into_cow_path( self ) -> Result< Cow<'a, Path>, io::Error >
71 {
72 Ok( Cow::Borrowed( self.as_std_path() ) )
73 }
74 }
75
76 #[cfg( feature = "path_utf8" )]
78 impl<'a> TryIntoCowPath<'a> for Utf8PathBuf
79 {
80 fn try_into_cow_path( self ) -> Result< Cow<'a, Path>, io::Error >
81 {
82 Ok( Cow::Owned( self.as_std_path().to_path_buf() ) )
83 }
84 }
85
86 impl<'a> TryIntoCowPath<'a> for Component<'a>
88 {
89 fn try_into_cow_path( self ) -> Result< Cow<'a, Path>, io::Error >
90 {
91 Ok( Cow::Owned( PathBuf::from( self.as_os_str() ) ) )
92 }
93 }
94
95 impl<'a, T> TryIntoCowPath< 'a > for &'a T
97 where
98 T : AsPath,
99 {
100 fn try_into_cow_path( self ) -> Result< Cow<'a, Path>, io::Error >
101 {
102 Ok( Cow::Borrowed( self.as_path() ) )
103 }
104 }
105
106}
107
108crate::mod_interface!
109{
110 orphan use TryIntoCowPath;
111}