@@ -17,13 +17,7 @@ use crate::{fmt, io, iter, mem, ptr, slice, str};
17
17
18
18
const TMPBUF_SZ : usize = 128 ;
19
19
20
- cfg_if:: cfg_if! {
21
- if #[ cfg( target_os = "redox" ) ] {
22
- const PATH_SEPARATOR : u8 = b';' ;
23
- } else {
24
- const PATH_SEPARATOR : u8 = b':' ;
25
- }
26
- }
20
+ const PATH_SEPARATOR : u8 = if cfg ! ( target_os = "redox" ) { b';' } else { b':' } ;
27
21
28
22
unsafe extern "C" {
29
23
#[ cfg( not( any( target_os = "dragonfly" , target_os = "vxworks" , target_os = "rtems" ) ) ) ]
@@ -193,33 +187,14 @@ pub fn chdir(p: &path::Path) -> io::Result<()> {
193
187
if result == 0 { Ok ( ( ) ) } else { Err ( io:: Error :: last_os_error ( ) ) }
194
188
}
195
189
196
- pub struct SplitPaths < ' a > {
197
- iter : iter:: Map < slice:: Split < ' a , u8 , fn ( & u8 ) -> bool > , fn ( & ' a [ u8 ] ) -> PathBuf > ,
198
- }
190
+ pub type SplitPaths < ' a > = impl Iterator < Item = PathBuf > ;
199
191
192
+ #[ define_opaque( SplitPaths ) ]
200
193
pub fn split_paths ( unparsed : & OsStr ) -> SplitPaths < ' _ > {
201
- fn bytes_to_path ( b : & [ u8 ] ) -> PathBuf {
202
- PathBuf :: from ( <OsStr as OsStrExt >:: from_bytes ( b) )
203
- }
204
- fn is_separator ( b : & u8 ) -> bool {
205
- * b == PATH_SEPARATOR
206
- }
207
- let unparsed = unparsed. as_bytes ( ) ;
208
- SplitPaths {
209
- iter : unparsed
210
- . split ( is_separator as fn ( & u8 ) -> bool )
211
- . map ( bytes_to_path as fn ( & [ u8 ] ) -> PathBuf ) ,
212
- }
213
- }
214
-
215
- impl < ' a > Iterator for SplitPaths < ' a > {
216
- type Item = PathBuf ;
217
- fn next ( & mut self ) -> Option < PathBuf > {
218
- self . iter . next ( )
219
- }
220
- fn size_hint ( & self ) -> ( usize , Option < usize > ) {
221
- self . iter . size_hint ( )
222
- }
194
+ unparsed
195
+ . as_bytes ( )
196
+ . split ( |& b| b == PATH_SEPARATOR )
197
+ . map ( |part| PathBuf :: from ( OsStr :: from_bytes ( part) ) )
223
198
}
224
199
225
200
#[ derive( Debug ) ]
0 commit comments