@@ -33,12 +33,12 @@ pub fn is_verbatim_sep(b: u8) -> bool {
3333
3434/// Returns true if `path` looks like a lone filename.
3535pub ( crate ) fn is_file_name ( path : & OsStr ) -> bool {
36- !path. bytes ( ) . iter ( ) . copied ( ) . any ( is_sep_byte)
36+ !path. as_os_str_bytes ( ) . iter ( ) . copied ( ) . any ( is_sep_byte)
3737}
3838pub ( crate ) fn has_trailing_slash ( path : & OsStr ) -> bool {
39- let is_verbatim = path. bytes ( ) . starts_with ( br"\\?\" ) ;
39+ let is_verbatim = path. as_os_str_bytes ( ) . starts_with ( br"\\?\" ) ;
4040 let is_separator = if is_verbatim { is_verbatim_sep } else { is_sep_byte } ;
41- if let Some ( & c) = path. bytes ( ) . last ( ) { is_separator ( c) } else { false }
41+ if let Some ( & c) = path. as_os_str_bytes ( ) . last ( ) { is_separator ( c) } else { false }
4242}
4343
4444/// Appends a suffix to a path.
@@ -60,7 +60,7 @@ impl<'a, const LEN: usize> PrefixParser<'a, LEN> {
6060 fn get_prefix ( path : & OsStr ) -> [ u8 ; LEN ] {
6161 let mut prefix = [ 0 ; LEN ] ;
6262 // SAFETY: Only ASCII characters are modified.
63- for ( i, & ch) in path. bytes ( ) . iter ( ) . take ( LEN ) . enumerate ( ) {
63+ for ( i, & ch) in path. as_os_str_bytes ( ) . iter ( ) . take ( LEN ) . enumerate ( ) {
6464 prefix[ i] = if ch == b'/' { b'\\' } else { ch } ;
6565 }
6666 prefix
@@ -93,15 +93,15 @@ impl<'a> PrefixParserSlice<'a, '_> {
9393 }
9494
9595 fn prefix_bytes ( & self ) -> & ' a [ u8 ] {
96- & self . path . bytes ( ) [ ..self . index ]
96+ & self . path . as_os_str_bytes ( ) [ ..self . index ]
9797 }
9898
9999 fn finish ( self ) -> & ' a OsStr {
100100 // SAFETY: The unsafety here stems from converting between &OsStr and
101101 // &[u8] and back. This is safe to do because (1) we only look at ASCII
102102 // contents of the encoding and (2) new &OsStr values are produced only
103103 // from ASCII-bounded slices of existing &OsStr values.
104- unsafe { bytes_as_os_str ( & self . path . bytes ( ) [ self . index ..] ) }
104+ unsafe { bytes_as_os_str ( & self . path . as_os_str_bytes ( ) [ self . index ..] ) }
105105 }
106106}
107107
@@ -173,7 +173,7 @@ fn parse_drive(path: &OsStr) -> Option<u8> {
173173 drive. is_ascii_alphabetic ( )
174174 }
175175
176- match path. bytes ( ) {
176+ match path. as_os_str_bytes ( ) {
177177 [ drive, b':' , ..] if is_valid_drive_letter ( drive) => Some ( drive. to_ascii_uppercase ( ) ) ,
178178 _ => None ,
179179 }
@@ -182,7 +182,7 @@ fn parse_drive(path: &OsStr) -> Option<u8> {
182182// Parses a drive prefix exactly, e.g. "C:"
183183fn parse_drive_exact ( path : & OsStr ) -> Option < u8 > {
184184 // only parse two bytes: the drive letter and the drive separator
185- if path. bytes ( ) . get ( 2 ) . map ( |& x| is_sep_byte ( x) ) . unwrap_or ( true ) {
185+ if path. as_os_str_bytes ( ) . get ( 2 ) . map ( |& x| is_sep_byte ( x) ) . unwrap_or ( true ) {
186186 parse_drive ( path)
187187 } else {
188188 None
@@ -196,15 +196,15 @@ fn parse_drive_exact(path: &OsStr) -> Option<u8> {
196196fn parse_next_component ( path : & OsStr , verbatim : bool ) -> ( & OsStr , & OsStr ) {
197197 let separator = if verbatim { is_verbatim_sep } else { is_sep_byte } ;
198198
199- match path. bytes ( ) . iter ( ) . position ( |& x| separator ( x) ) {
199+ match path. as_os_str_bytes ( ) . iter ( ) . position ( |& x| separator ( x) ) {
200200 Some ( separator_start) => {
201201 let separator_end = separator_start + 1 ;
202202
203- let component = & path. bytes ( ) [ ..separator_start] ;
203+ let component = & path. as_os_str_bytes ( ) [ ..separator_start] ;
204204
205205 // Panic safe
206206 // The max `separator_end` is `bytes.len()` and `bytes[bytes.len()..]` is a valid index.
207- let path = & path. bytes ( ) [ separator_end..] ;
207+ let path = & path. as_os_str_bytes ( ) [ separator_end..] ;
208208
209209 // SAFETY: `path` is a valid wtf8 encoded slice and each of the separators ('/', '\')
210210 // is encoded in a single byte, therefore `bytes[separator_start]` and
@@ -329,7 +329,7 @@ pub(crate) fn absolute(path: &Path) -> io::Result<PathBuf> {
329329 // Verbatim paths should not be modified.
330330 if prefix. map ( |x| x. is_verbatim ( ) ) . unwrap_or ( false ) {
331331 // NULs in verbatim paths are rejected for consistency.
332- if path. bytes ( ) . contains ( & 0 ) {
332+ if path. as_os_str_bytes ( ) . contains ( & 0 ) {
333333 return Err ( io:: const_io_error!(
334334 io:: ErrorKind :: InvalidInput ,
335335 "strings passed to WinAPI cannot contain NULs" ,
0 commit comments