@@ -341,25 +341,37 @@ pub fn relativize_with_prefix<'a>(relative_path: &'a Path, prefix: &Path) -> Cow
341
341
}
342
342
}
343
343
344
- /// The error used in [`ToPathComponents::to_components()`][crate::convert::ToPathComponents::to_components()].
345
- #[ derive( Debug , thiserror:: Error ) ]
346
- #[ allow( missing_docs) ]
347
- pub enum Error < ' a > {
348
- #[ error( "Input path {path:?} contains relative or absolute components" , path = . 0 ) ]
349
- NotANormalComponent ( & ' a OsStr ) ,
344
+ ///
345
+ pub mod to_normal_path_components {
346
+ use std:: ffi:: OsString ;
347
+
348
+ /// The error used in [`ToNormalPathComponents::to_normal_path_components()`](crate::ToNormalPathComponents::to_normal_path_components()).
349
+ #[ derive( Debug , thiserror:: Error ) ]
350
+ #[ allow( missing_docs) ]
351
+ pub enum Error {
352
+ #[ error( "Input path {path:?} contains relative or absolute components" , path = . 0 ) ]
353
+ NotANormalComponent ( OsString ) ,
354
+ }
350
355
}
351
356
352
- /// Obtain an iterator over `OsStr`-components.
353
- pub trait ToPathComponents {
354
- /// Return an iterator over the components of a path, without the separator.
355
- fn to_components ( & self ) -> impl Iterator < Item = Result < & OsStr , Error < ' _ > > > ;
357
+ /// Obtain an iterator over `OsStr`-components which are normal, none-relative and not absolute.
358
+ pub trait ToNormalPathComponents {
359
+ /// Return an iterator over the normal components of a path, without the separator.
360
+ // TODO(MSRV): turn this into `impl Iterator` once MSRV is 1.75 or higher
361
+ fn to_normal_path_components (
362
+ & self ,
363
+ ) -> Box < dyn Iterator < Item = Result < & OsStr , to_normal_path_components:: Error > > + ' _ > ;
356
364
}
357
365
358
- impl ToPathComponents for & Path {
359
- fn to_components ( & self ) -> impl Iterator < Item = Result < & OsStr , Error < ' _ > > > {
360
- self . components ( ) . map ( |component| match component {
366
+ impl ToNormalPathComponents for & Path {
367
+ fn to_normal_path_components (
368
+ & self ,
369
+ ) -> Box < dyn Iterator < Item = Result < & OsStr , to_normal_path_components:: Error > > + ' _ > {
370
+ Box :: new ( self . components ( ) . map ( |component| match component {
361
371
Component :: Normal ( os_str) => Ok ( os_str) ,
362
- _ => Err ( Error :: NotANormalComponent ( self . as_os_str ( ) ) ) ,
363
- } )
372
+ _ => Err ( to_normal_path_components:: Error :: NotANormalComponent (
373
+ self . as_os_str ( ) . to_owned ( ) ,
374
+ ) ) ,
375
+ } ) )
364
376
}
365
377
}
0 commit comments