Skip to content

Commit c643575

Browse files
committed
add basic support of OsStrExt for HermitCore
this patch increases the compatibility to other operating systems
1 parent 57e1da5 commit c643575

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

src/libstd/os/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ cfg_if::cfg_if! {
2424
// If we're not documenting libstd then we just expose the main modules
2525
// as we otherwise would.
2626

27-
#[cfg(any(target_os = "redox", unix, target_os = "vxworks"))]
27+
#[cfg(any(target_os = "redox", unix, target_os = "vxworks", target_os = "hermit"))]
2828
#[stable(feature = "rust1", since = "1.0.0")]
2929
pub use crate::sys::ext as unix;
3030

src/libstd/sys/hermit/ext/ffi.rs

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//! HermitCore-specific extension to the primitives in the `std::ffi` module
2+
//!
3+
//! # Examples
4+
//!
5+
//! ```
6+
//! use std::ffi::OsString;
7+
//! use std::os::hermit::ffi::OsStringExt;
8+
//!
9+
//! let bytes = b"foo".to_vec();
10+
//!
11+
//! // OsStringExt::from_vec
12+
//! let os_string = OsString::from_vec(bytes);
13+
//! assert_eq!(os_string.to_str(), Some("foo"));
14+
//!
15+
//! // OsStringExt::into_vec
16+
//! let bytes = os_string.into_vec();
17+
//! assert_eq!(bytes, b"foo");
18+
//! ```
19+
//!
20+
//! ```
21+
//! use std::ffi::OsStr;
22+
//! use std::os::hermit::ffi::OsStrExt;
23+
//!
24+
//! let bytes = b"foo";
25+
//!
26+
//! // OsStrExt::from_bytes
27+
//! let os_str = OsStr::from_bytes(bytes);
28+
//! assert_eq!(os_str.to_str(), Some("foo"));
29+
//!
30+
//! // OsStrExt::as_bytes
31+
//! let bytes = os_str.as_bytes();
32+
//! assert_eq!(bytes, b"foo");
33+
//! ```
34+
35+
#![stable(feature = "rust1", since = "1.0.0")]
36+
37+
#[stable(feature = "rust1", since = "1.0.0")]
38+
pub use crate::sys_common::os_str_bytes::*;

src/libstd/sys/hermit/ext/mod.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![stable(feature = "rust1", since = "1.0.0")]
2+
#![allow(missing_docs)]
3+
4+
pub mod ffi;
5+
6+
/// A prelude for conveniently writing platform-specific code.
7+
///
8+
/// Includes all extension traits, and some important type definitions.
9+
#[stable(feature = "rust1", since = "1.0.0")]
10+
pub mod prelude {
11+
#[doc(no_inline)]
12+
#[stable(feature = "rust1", since = "1.0.0")]
13+
pub use super::ffi::{OsStrExt, OsStringExt};
14+
}

src/libstd/sys/hermit/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub mod args;
2121
pub mod cmath;
2222
pub mod condvar;
2323
pub mod env;
24+
pub mod ext;
2425
pub mod fast_thread_local;
2526
pub mod fd;
2627
pub mod fs;

0 commit comments

Comments
 (0)