1mod private
3{
4 #[ allow( unused_imports, clippy::wildcard_imports ) ]
5 use crate::*;
6 use std::
7 {
8 io,
9 path::{ Component, Path, PathBuf },
10 };
11 pub trait TryIntoPath
19 {
20 fn try_into_path( self ) -> Result< PathBuf, io::Error >;
29 }
30
31 impl TryIntoPath for &str
33 {
34 fn try_into_path( self ) -> Result< PathBuf, io::Error >
35 {
36 Ok( PathBuf::from( self ) )
37 }
38 }
39
40 impl TryIntoPath for String
42 {
43 fn try_into_path( self ) -> Result< PathBuf, io::Error >
44 {
45 Ok( PathBuf::from( self ) )
46 }
47 }
48
49 impl TryIntoPath for &Path
51 {
52 fn try_into_path( self ) -> Result< PathBuf, io::Error >
53 {
54 Ok( self.to_path_buf() )
55 }
56 }
57
58 impl TryIntoPath for PathBuf
60 {
61 fn try_into_path( self ) -> Result< PathBuf, io::Error >
62 {
63 Ok( self )
64 }
65 }
66
67 #[cfg( feature = "path_utf8" )]
69 impl TryIntoPath for &Utf8Path
70 {
71 fn try_into_path( self ) -> Result< PathBuf, io::Error >
72 {
73 Ok( self.as_std_path().to_path_buf() )
74 }
75 }
76
77 #[cfg( feature = "path_utf8" )]
79 impl TryIntoPath for Utf8PathBuf
80 {
81 fn try_into_path( self ) -> Result< PathBuf, io::Error >
82 {
83 Ok( self.as_std_path().to_path_buf() )
84 }
85 }
86
87 impl TryIntoPath for Component<'_>
89 {
90 fn try_into_path( self ) -> Result< PathBuf, io::Error >
91 {
92 Ok( self.as_os_str().into() )
93 }
94 }
95
96 impl< T > TryIntoPath for &T
98 where
99 T : AsRef< Path >,
100 {
101 fn try_into_path( self ) -> Result< PathBuf, io::Error >
102 {
103 Ok( self.as_ref().to_path_buf() )
104 }
105 }
106}
107
108crate::mod_interface!
109{
110 orphan use TryIntoPath;
111}