1mod private
3{
4 #[ allow( unused_imports, clippy ::wildcard_imports ) ]
5 #[ allow( clippy ::std_instead_of_alloc, clippy ::std_instead_of_core ) ]
6 use crate :: *;
7
8 #[ cfg( not( feature = "no_std" ) ) ]
9 use std ::
10 {
11 io,
12 path :: { Component, Path, PathBuf },
13 string ::String,
14 };
15
16 #[ cfg( feature = "no_std" ) ]
17 extern crate std;
18
19 #[ cfg( feature = "no_std" ) ]
20 use std ::
21 {
22 io,
23 path :: { Component, Path, PathBuf },
24 };
25
26 #[ cfg( feature = "no_std" ) ]
27 use alloc ::string ::String;
28
29 pub trait TryIntoPath
35 {
36 fn try_into_path( self ) -> Result< PathBuf, io ::Error >;
45 }
46
47 impl TryIntoPath for &str
49 {
50 fn try_into_path( self ) -> Result< PathBuf, io ::Error >
51 {
52 Ok( PathBuf ::from( self ) )
53 }
54 }
55
56 impl TryIntoPath for String
58 {
59 fn try_into_path( self ) -> Result< PathBuf, io ::Error >
60 {
61 Ok( PathBuf ::from( self ) )
62 }
63 }
64
65 impl TryIntoPath for &Path
67 {
68 fn try_into_path( self ) -> Result< PathBuf, io ::Error >
69 {
70 Ok( self.to_path_buf() )
71 }
72 }
73
74 impl TryIntoPath for PathBuf
76 {
77 fn try_into_path( self ) -> Result< PathBuf, io ::Error >
78 {
79 Ok( self )
80 }
81 }
82
83 #[ cfg( feature = "path_utf8" ) ]
85 impl TryIntoPath for &Utf8Path
86 {
87 fn try_into_path( self ) -> Result< PathBuf, io ::Error >
88 {
89 Ok( self.as_std_path().to_path_buf() )
90 }
91 }
92
93 #[ cfg( feature = "path_utf8" ) ]
95 impl TryIntoPath for Utf8PathBuf
96 {
97 fn try_into_path( self ) -> Result< PathBuf, io ::Error >
98 {
99 Ok( self.as_std_path().to_path_buf() )
100 }
101 }
102
103 impl TryIntoPath for Component< '_ >
105 {
106 fn try_into_path( self ) -> Result< PathBuf, io ::Error >
107 {
108 Ok( self.as_os_str().into() )
109 }
110 }
111
112 impl< T > TryIntoPath for &T
114 where
115 T: AsRef< Path >,
116 {
117 fn try_into_path( self ) -> Result< PathBuf, io ::Error >
118 {
119 Ok( self.as_ref().to_path_buf() )
120 }
121 }
122}
123
124crate ::mod_interface!
125{
126 orphan use TryIntoPath;
127}