Skip to content

Commit 1a96d22

Browse files
committed
Move OsStringExt and OsStrExt to std::os
1 parent 39260f6 commit 1a96d22

File tree

9 files changed

+85
-70
lines changed

9 files changed

+85
-70
lines changed

library/std/src/os/fortanix_sgx/ffi.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,8 @@
3434
3535
#![unstable(feature = "sgx_platform", issue = "56975")]
3636

37+
#[path = "../unix/ffi/os_str.rs"]
38+
mod os_str;
39+
3740
#[unstable(feature = "sgx_platform", issue = "56975")]
38-
pub use crate::sys_common::os_str_bytes::*;
41+
pub use self::os_str::{OsStrExt, OsStringExt};

library/std/src/os/hermit/ffi.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,8 @@
3434
3535
#![stable(feature = "rust1", since = "1.0.0")]
3636

37+
#[path = "../unix/ffi/os_str.rs"]
38+
mod os_str;
39+
3740
#[stable(feature = "rust1", since = "1.0.0")]
38-
pub use crate::sys_common::os_str_bytes::*;
41+
pub use self::os_str::{OsStrExt, OsStringExt};

library/std/src/os/unix/ffi.rs renamed to library/std/src/os/unix/ffi/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,7 @@
3434
3535
#![stable(feature = "rust1", since = "1.0.0")]
3636

37+
mod os_str;
38+
3739
#[stable(feature = "rust1", since = "1.0.0")]
38-
pub use crate::sys_common::os_str_bytes::*;
40+
pub use self::os_str::{OsStrExt, OsStringExt};

library/std/src/os/unix/ffi/os_str.rs

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
use crate::ffi::{OsStr, OsString};
2+
use crate::mem;
3+
use crate::sealed::Sealed;
4+
use crate::sys::os_str::Buf;
5+
use crate::sys_common::{AsInner, FromInner, IntoInner};
6+
7+
/// Platform-specific extensions to [`OsString`].
8+
///
9+
/// This trait is sealed: it cannot be implemented outside the standard library.
10+
/// This is so that future additional methods are not breaking changes.
11+
#[stable(feature = "rust1", since = "1.0.0")]
12+
pub trait OsStringExt: Sealed {
13+
/// Creates an [`OsString`] from a byte vector.
14+
///
15+
/// See the module documentation for an example.
16+
#[stable(feature = "rust1", since = "1.0.0")]
17+
fn from_vec(vec: Vec<u8>) -> Self;
18+
19+
/// Yields the underlying byte vector of this [`OsString`].
20+
///
21+
/// See the module documentation for an example.
22+
#[stable(feature = "rust1", since = "1.0.0")]
23+
fn into_vec(self) -> Vec<u8>;
24+
}
25+
26+
#[stable(feature = "rust1", since = "1.0.0")]
27+
impl OsStringExt for OsString {
28+
fn from_vec(vec: Vec<u8>) -> OsString {
29+
FromInner::from_inner(Buf { inner: vec })
30+
}
31+
fn into_vec(self) -> Vec<u8> {
32+
self.into_inner().inner
33+
}
34+
}
35+
36+
/// Platform-specific extensions to [`OsStr`].
37+
///
38+
/// This trait is sealed: it cannot be implemented outside the standard library.
39+
/// This is so that future additional methods are not breaking changes.
40+
#[stable(feature = "rust1", since = "1.0.0")]
41+
pub trait OsStrExt: Sealed {
42+
#[stable(feature = "rust1", since = "1.0.0")]
43+
/// Creates an [`OsStr`] from a byte slice.
44+
///
45+
/// See the module documentation for an example.
46+
fn from_bytes(slice: &[u8]) -> &Self;
47+
48+
/// Gets the underlying byte view of the [`OsStr`] slice.
49+
///
50+
/// See the module documentation for an example.
51+
#[stable(feature = "rust1", since = "1.0.0")]
52+
fn as_bytes(&self) -> &[u8];
53+
}
54+
55+
#[stable(feature = "rust1", since = "1.0.0")]
56+
impl OsStrExt for OsStr {
57+
#[inline]
58+
fn from_bytes(slice: &[u8]) -> &OsStr {
59+
unsafe { mem::transmute(slice) }
60+
}
61+
#[inline]
62+
fn as_bytes(&self) -> &[u8] {
63+
&self.as_inner().inner
64+
}
65+
}

library/std/src/os/wasi/ffi.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
33
#![stable(feature = "rust1", since = "1.0.0")]
44

5+
#[path = "../unix/ffi/os_str.rs"]
6+
mod os_str;
7+
58
#[stable(feature = "rust1", since = "1.0.0")]
6-
pub use crate::sys_common::os_str_bytes::*;
9+
pub use self::os_str::{OsStrExt, OsStringExt};

library/std/src/sys/hermit/args.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ impl DoubleEndedIterator for Args {
5555
mod imp {
5656
use super::Args;
5757
use crate::ffi::{CStr, OsString};
58+
use crate::os::unix::ffi::OsStringExt;
5859
use crate::ptr;
59-
use crate::sys_common::os_str_bytes::*;
6060

6161
use crate::sys_common::mutex::StaticMutex;
6262

library/std/src/sys/hermit/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ use crate::fmt;
33
use crate::hash::{Hash, Hasher};
44
use crate::io::{self, Error, ErrorKind};
55
use crate::io::{IoSlice, IoSliceMut, SeekFrom};
6+
use crate::os::unix::ffi::OsStrExt;
67
use crate::path::{Path, PathBuf};
78
use crate::sys::cvt;
89
use crate::sys::hermit::abi;
910
use crate::sys::hermit::abi::{O_APPEND, O_CREAT, O_EXCL, O_RDONLY, O_RDWR, O_TRUNC, O_WRONLY};
1011
use crate::sys::hermit::fd::FileDesc;
1112
use crate::sys::time::SystemTime;
1213
use crate::sys::unsupported;
13-
use crate::sys_common::os_str_bytes::OsStrExt;
1414

1515
pub use crate::sys_common::fs::{copy, try_exists};
1616
//pub use crate::sys_common::fs::remove_dir_all;

library/std/src/sys/hermit/os.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ use crate::ffi::{CStr, OsStr, OsString};
44
use crate::fmt;
55
use crate::io;
66
use crate::marker::PhantomData;
7+
use crate::os::unix::ffi::OsStringExt;
78
use crate::path::{self, PathBuf};
89
use crate::str;
910
use crate::sync::Mutex;
1011
use crate::sys::hermit::abi;
1112
use crate::sys::memchr;
1213
use crate::sys::unsupported;
13-
use crate::sys_common::os_str_bytes::*;
1414
use crate::vec;
1515

1616
pub fn errno() -> i32 {

library/std/src/sys_common/os_str_bytes.rs

+2-63
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
//! systems: just a `Vec<u8>`/`[u8]`.
33
44
use crate::borrow::Cow;
5-
use crate::ffi::{OsStr, OsString};
5+
66
use crate::fmt;
77
use crate::mem;
88
use crate::rc::Rc;
9-
use crate::sealed::Sealed;
109
use crate::str;
1110
use crate::sync::Arc;
1211
use crate::sys_common::bytestring::debug_fmt_bytestring;
13-
use crate::sys_common::{AsInner, FromInner, IntoInner};
12+
use crate::sys_common::{AsInner, IntoInner};
1413

1514
use core::str::lossy::Utf8Lossy;
1615

@@ -243,63 +242,3 @@ impl Slice {
243242
self.inner.eq_ignore_ascii_case(&other.inner)
244243
}
245244
}
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

Comments
 (0)