|
2 | 2 | //! systems: just a `Vec<u8>`/`[u8]`. |
3 | 3 |
|
4 | 4 | use crate::borrow::Cow; |
5 | | -use crate::ffi::{OsStr, OsString}; |
| 5 | + |
6 | 6 | use crate::fmt; |
7 | 7 | use crate::mem; |
8 | 8 | use crate::rc::Rc; |
9 | | -use crate::sealed::Sealed; |
10 | 9 | use crate::str; |
11 | 10 | use crate::sync::Arc; |
12 | 11 | use crate::sys_common::bytestring::debug_fmt_bytestring; |
13 | | -use crate::sys_common::{AsInner, FromInner, IntoInner}; |
| 12 | +use crate::sys_common::{AsInner, IntoInner}; |
14 | 13 |
|
15 | 14 | use core::str::lossy::Utf8Lossy; |
16 | 15 |
|
17 | 16 | #[derive(Hash)] |
18 | | -pub(crate) struct Buf { |
| 17 | +#[repr(transparent)] |
| 18 | +pub struct Buf { |
19 | 19 | pub inner: Vec<u8>, |
20 | 20 | } |
21 | 21 |
|
22 | | -// FIXME: |
23 | | -// `Buf::as_slice` current implementation relies |
24 | | -// on `Slice` being layout-compatible with `[u8]`. |
25 | | -// When attribute privacy is implemented, `Slice` should be annotated as `#[repr(transparent)]`. |
26 | | -// Anyway, `Slice` representation and layout are considered implementation detail, are |
27 | | -// not documented and must not be relied upon. |
28 | | -pub(crate) struct Slice { |
| 22 | +#[repr(transparent)] |
| 23 | +pub struct Slice { |
29 | 24 | pub inner: [u8], |
30 | 25 | } |
31 | 26 |
|
@@ -243,63 +238,3 @@ impl Slice { |
243 | 238 | self.inner.eq_ignore_ascii_case(&other.inner) |
244 | 239 | } |
245 | 240 | } |
246 | | - |
247 | | -/// Platform-specific extensions to [`OsString`]. |
248 | | -/// |
249 | | -/// This trait is sealed: it cannot be implemented outside the standard library. |
250 | | -/// This is so that future additional methods are not breaking changes. |
251 | | -#[stable(feature = "rust1", since = "1.0.0")] |
252 | | -pub trait OsStringExt: Sealed { |
253 | | - /// Creates an [`OsString`] from a byte vector. |
254 | | - /// |
255 | | - /// See the module documentation for an example. |
256 | | - #[stable(feature = "rust1", since = "1.0.0")] |
257 | | - fn from_vec(vec: Vec<u8>) -> Self; |
258 | | - |
259 | | - /// Yields the underlying byte vector of this [`OsString`]. |
260 | | - /// |
261 | | - /// See the module documentation for an example. |
262 | | - #[stable(feature = "rust1", since = "1.0.0")] |
263 | | - fn into_vec(self) -> Vec<u8>; |
264 | | -} |
265 | | - |
266 | | -#[stable(feature = "rust1", since = "1.0.0")] |
267 | | -impl OsStringExt for OsString { |
268 | | - fn from_vec(vec: Vec<u8>) -> OsString { |
269 | | - FromInner::from_inner(Buf { inner: vec }) |
270 | | - } |
271 | | - fn into_vec(self) -> Vec<u8> { |
272 | | - self.into_inner().inner |
273 | | - } |
274 | | -} |
275 | | - |
276 | | -/// Platform-specific extensions to [`OsStr`]. |
277 | | -/// |
278 | | -/// This trait is sealed: it cannot be implemented outside the standard library. |
279 | | -/// This is so that future additional methods are not breaking changes. |
280 | | -#[stable(feature = "rust1", since = "1.0.0")] |
281 | | -pub trait OsStrExt: Sealed { |
282 | | - #[stable(feature = "rust1", since = "1.0.0")] |
283 | | - /// Creates an [`OsStr`] from a byte slice. |
284 | | - /// |
285 | | - /// See the module documentation for an example. |
286 | | - fn from_bytes(slice: &[u8]) -> &Self; |
287 | | - |
288 | | - /// Gets the underlying byte view of the [`OsStr`] slice. |
289 | | - /// |
290 | | - /// See the module documentation for an example. |
291 | | - #[stable(feature = "rust1", since = "1.0.0")] |
292 | | - fn as_bytes(&self) -> &[u8]; |
293 | | -} |
294 | | - |
295 | | -#[stable(feature = "rust1", since = "1.0.0")] |
296 | | -impl OsStrExt for OsStr { |
297 | | - #[inline] |
298 | | - fn from_bytes(slice: &[u8]) -> &OsStr { |
299 | | - unsafe { mem::transmute(slice) } |
300 | | - } |
301 | | - #[inline] |
302 | | - fn as_bytes(&self) -> &[u8] { |
303 | | - &self.as_inner().inner |
304 | | - } |
305 | | -} |
0 commit comments