@@ -154,36 +154,34 @@ impl OsString {
154
154
/// # Safety
155
155
///
156
156
/// As the encoding is unspecified, callers must pass in bytes that originated as a mixture of
157
- /// validated UTF-8 and bytes from [`OsStr::as_os_str_bytes `] from within the same rust version
157
+ /// validated UTF-8 and bytes from [`OsStr::as_encoded_bytes `] from within the same rust version
158
158
/// built for the same target platform. For example, reconstructing an `OsString` from bytes sent
159
159
/// over the network or stored in a file will likely violate these safety rules.
160
160
///
161
- /// Due to the encoding being self-synchronizing, the bytes from [`OsStr::as_os_str_bytes `] can be
161
+ /// Due to the encoding being self-synchronizing, the bytes from [`OsStr::as_encoded_bytes `] can be
162
162
/// split either immediately before or immediately after any valid non-empty UTF-8 substring.
163
163
///
164
164
/// # Example
165
165
///
166
166
/// ```
167
- /// #![feature(os_str_bytes)]
168
- ///
169
167
/// use std::ffi::OsStr;
170
168
///
171
169
/// let os_str = OsStr::new("Mary had a little lamb");
172
- /// let bytes = os_str.as_os_str_bytes ();
170
+ /// let bytes = os_str.as_encoded_bytes ();
173
171
/// let words = bytes.split(|b| *b == b' ');
174
172
/// let words: Vec<&OsStr> = words.map(|word| {
175
173
/// // SAFETY:
176
- /// // - Each `word` only contains content that originated from `OsStr::as_os_str_bytes `
174
+ /// // - Each `word` only contains content that originated from `OsStr::as_encoded_bytes `
177
175
/// // - Only split with ASCII whitespace which is a non-empty UTF-8 substring
178
- /// unsafe { OsStr::from_os_str_bytes_unchecked (word) }
176
+ /// unsafe { OsStr::from_encoded_bytes_unchecked (word) }
179
177
/// }).collect();
180
178
/// ```
181
179
///
182
180
/// [conversions]: super#conversions
183
181
#[ inline]
184
- #[ unstable ( feature = "os_str_bytes" , issue = "111544 " ) ]
185
- pub unsafe fn from_os_str_bytes_unchecked ( bytes : Vec < u8 > ) -> Self {
186
- OsString { inner : Buf :: from_os_str_bytes_unchecked ( bytes) }
182
+ #[ stable ( feature = "os_str_bytes" , since = "CURRENT_RUSTC_VERSION " ) ]
183
+ pub unsafe fn from_encoded_bytes_unchecked ( bytes : Vec < u8 > ) -> Self {
184
+ OsString { inner : Buf :: from_encoded_bytes_unchecked ( bytes) }
187
185
}
188
186
189
187
/// Converts to an [`OsStr`] slice.
@@ -205,7 +203,7 @@ impl OsString {
205
203
}
206
204
207
205
/// Converts the `OsString` into a byte slice. To convert the byte slice back into an
208
- /// `OsString`, use the [`OsStr::from_os_str_bytes_unchecked `] function.
206
+ /// `OsString`, use the [`OsStr::from_encoded_bytes_unchecked `] function.
209
207
///
210
208
/// The byte encoding is an unspecified, platform-specific, self-synchronizing superset of UTF-8.
211
209
/// By being a self-synchronizing superset of UTF-8, this encoding is also a superset of 7-bit
@@ -219,9 +217,9 @@ impl OsString {
219
217
///
220
218
/// [`std::ffi`]: crate::ffi
221
219
#[ inline]
222
- #[ unstable ( feature = "os_str_bytes" , issue = "111544 " ) ]
223
- pub fn into_os_str_bytes ( self ) -> Vec < u8 > {
224
- self . inner . into_os_str_bytes ( )
220
+ #[ stable ( feature = "os_str_bytes" , since = "CURRENT_RUSTC_VERSION " ) ]
221
+ pub fn into_encoded_bytes ( self ) -> Vec < u8 > {
222
+ self . inner . into_encoded_bytes ( )
225
223
}
226
224
227
225
/// Converts the `OsString` into a [`String`] if it contains valid Unicode data.
@@ -745,36 +743,34 @@ impl OsStr {
745
743
/// # Safety
746
744
///
747
745
/// As the encoding is unspecified, callers must pass in bytes that originated as a mixture of
748
- /// validated UTF-8 and bytes from [`OsStr::as_os_str_bytes `] from within the same rust version
746
+ /// validated UTF-8 and bytes from [`OsStr::as_encoded_bytes `] from within the same rust version
749
747
/// built for the same target platform. For example, reconstructing an `OsStr` from bytes sent
750
748
/// over the network or stored in a file will likely violate these safety rules.
751
749
///
752
- /// Due to the encoding being self-synchronizing, the bytes from [`OsStr::as_os_str_bytes `] can be
750
+ /// Due to the encoding being self-synchronizing, the bytes from [`OsStr::as_encoded_bytes `] can be
753
751
/// split either immediately before or immediately after any valid non-empty UTF-8 substring.
754
752
///
755
753
/// # Example
756
754
///
757
755
/// ```
758
- /// #![feature(os_str_bytes)]
759
- ///
760
756
/// use std::ffi::OsStr;
761
757
///
762
758
/// let os_str = OsStr::new("Mary had a little lamb");
763
- /// let bytes = os_str.as_os_str_bytes ();
759
+ /// let bytes = os_str.as_encoded_bytes ();
764
760
/// let words = bytes.split(|b| *b == b' ');
765
761
/// let words: Vec<&OsStr> = words.map(|word| {
766
762
/// // SAFETY:
767
- /// // - Each `word` only contains content that originated from `OsStr::as_os_str_bytes `
763
+ /// // - Each `word` only contains content that originated from `OsStr::as_encoded_bytes `
768
764
/// // - Only split with ASCII whitespace which is a non-empty UTF-8 substring
769
- /// unsafe { OsStr::from_os_str_bytes_unchecked (word) }
765
+ /// unsafe { OsStr::from_encoded_bytes_unchecked (word) }
770
766
/// }).collect();
771
767
/// ```
772
768
///
773
769
/// [conversions]: super#conversions
774
770
#[ inline]
775
- #[ unstable ( feature = "os_str_bytes" , issue = "111544 " ) ]
776
- pub unsafe fn from_os_str_bytes_unchecked ( bytes : & [ u8 ] ) -> & Self {
777
- Self :: from_inner ( Slice :: from_os_str_bytes_unchecked ( bytes) )
771
+ #[ stable ( feature = "os_str_bytes" , since = "CURRENT_RUSTC_VERSION " ) ]
772
+ pub unsafe fn from_encoded_bytes_unchecked ( bytes : & [ u8 ] ) -> & Self {
773
+ Self :: from_inner ( Slice :: from_encoded_bytes_unchecked ( bytes) )
778
774
}
779
775
780
776
#[ inline]
@@ -948,7 +944,7 @@ impl OsStr {
948
944
}
949
945
950
946
/// Converts an OS string slice to a byte slice. To convert the byte slice back into an OS
951
- /// string slice, use the [`OsStr::from_os_str_bytes_unchecked `] function.
947
+ /// string slice, use the [`OsStr::from_encoded_bytes_unchecked `] function.
952
948
///
953
949
/// The byte encoding is an unspecified, platform-specific, self-synchronizing superset of UTF-8.
954
950
/// By being a self-synchronizing superset of UTF-8, this encoding is also a superset of 7-bit
@@ -962,9 +958,9 @@ impl OsStr {
962
958
///
963
959
/// [`std::ffi`]: crate::ffi
964
960
#[ inline]
965
- #[ unstable ( feature = "os_str_bytes" , issue = "111544 " ) ]
966
- pub fn as_os_str_bytes ( & self ) -> & [ u8 ] {
967
- self . inner . as_os_str_bytes ( )
961
+ #[ stable ( feature = "os_str_bytes" , since = "CURRENT_RUSTC_VERSION " ) ]
962
+ pub fn as_encoded_bytes ( & self ) -> & [ u8 ] {
963
+ self . inner . as_encoded_bytes ( )
968
964
}
969
965
970
966
/// Converts this string to its ASCII lower case equivalent in-place.
@@ -1270,7 +1266,7 @@ impl Default for &OsStr {
1270
1266
impl PartialEq for OsStr {
1271
1267
#[ inline]
1272
1268
fn eq ( & self , other : & OsStr ) -> bool {
1273
- self . as_os_str_bytes ( ) . eq ( other. as_os_str_bytes ( ) )
1269
+ self . as_encoded_bytes ( ) . eq ( other. as_encoded_bytes ( ) )
1274
1270
}
1275
1271
}
1276
1272
@@ -1297,23 +1293,23 @@ impl Eq for OsStr {}
1297
1293
impl PartialOrd for OsStr {
1298
1294
#[ inline]
1299
1295
fn partial_cmp ( & self , other : & OsStr ) -> Option < cmp:: Ordering > {
1300
- self . as_os_str_bytes ( ) . partial_cmp ( other. as_os_str_bytes ( ) )
1296
+ self . as_encoded_bytes ( ) . partial_cmp ( other. as_encoded_bytes ( ) )
1301
1297
}
1302
1298
#[ inline]
1303
1299
fn lt ( & self , other : & OsStr ) -> bool {
1304
- self . as_os_str_bytes ( ) . lt ( other. as_os_str_bytes ( ) )
1300
+ self . as_encoded_bytes ( ) . lt ( other. as_encoded_bytes ( ) )
1305
1301
}
1306
1302
#[ inline]
1307
1303
fn le ( & self , other : & OsStr ) -> bool {
1308
- self . as_os_str_bytes ( ) . le ( other. as_os_str_bytes ( ) )
1304
+ self . as_encoded_bytes ( ) . le ( other. as_encoded_bytes ( ) )
1309
1305
}
1310
1306
#[ inline]
1311
1307
fn gt ( & self , other : & OsStr ) -> bool {
1312
- self . as_os_str_bytes ( ) . gt ( other. as_os_str_bytes ( ) )
1308
+ self . as_encoded_bytes ( ) . gt ( other. as_encoded_bytes ( ) )
1313
1309
}
1314
1310
#[ inline]
1315
1311
fn ge ( & self , other : & OsStr ) -> bool {
1316
- self . as_os_str_bytes ( ) . ge ( other. as_os_str_bytes ( ) )
1312
+ self . as_encoded_bytes ( ) . ge ( other. as_encoded_bytes ( ) )
1317
1313
}
1318
1314
}
1319
1315
@@ -1332,7 +1328,7 @@ impl PartialOrd<str> for OsStr {
1332
1328
impl Ord for OsStr {
1333
1329
#[ inline]
1334
1330
fn cmp ( & self , other : & OsStr ) -> cmp:: Ordering {
1335
- self . as_os_str_bytes ( ) . cmp ( other. as_os_str_bytes ( ) )
1331
+ self . as_encoded_bytes ( ) . cmp ( other. as_encoded_bytes ( ) )
1336
1332
}
1337
1333
}
1338
1334
@@ -1382,7 +1378,7 @@ impl_cmp!(Cow<'a, OsStr>, OsString);
1382
1378
impl Hash for OsStr {
1383
1379
#[ inline]
1384
1380
fn hash < H : Hasher > ( & self , state : & mut H ) {
1385
- self . as_os_str_bytes ( ) . hash ( state)
1381
+ self . as_encoded_bytes ( ) . hash ( state)
1386
1382
}
1387
1383
}
1388
1384
0 commit comments