Skip to main content

std/os/unix/ffi/
mod.rs

1//! Unix-specific extensions to primitives in the [`std::ffi`] module.
2//!
3//! # Examples
4//!
5#![cfg_attr(target_family = "unix", doc = "```")]
6#![cfg_attr(not(target_family = "unix"), doc = "```ignore (needs unix)")]
7//! use std::ffi::OsString;
8//! use std::os::unix::ffi::OsStringExt;
9//!
10//! let bytes = b"foo".to_vec();
11//!
12//! // OsStringExt::from_vec
13//! let os_string = OsString::from_vec(bytes);
14//! assert_eq!(os_string.to_str(), Some("foo"));
15//!
16//! // OsStringExt::into_vec
17//! let bytes = os_string.into_vec();
18//! assert_eq!(bytes, b"foo");
19//! ```
20//!
21#![cfg_attr(target_family = "unix", doc = "```")]
22#![cfg_attr(not(target_family = "unix"), doc = "```ignore (needs unix)")]
23//! use std::ffi::OsStr;
24//! use std::os::unix::ffi::OsStrExt;
25//!
26//! let bytes = b"foo";
27//!
28//! // OsStrExt::from_bytes
29//! let os_str = OsStr::from_bytes(bytes);
30//! assert_eq!(os_str.to_str(), Some("foo"));
31//!
32//! // OsStrExt::as_bytes
33//! let bytes = os_str.as_bytes();
34//! assert_eq!(bytes, b"foo");
35//! ```
36//!
37//! [`std::ffi`]: crate::ffi
38
39#![stable(feature = "rust1", since = "1.0.0")]
40
41mod os_str;
42
43#[stable(feature = "rust1", since = "1.0.0")]
44pub use self::os_str::{OsStrExt, OsStringExt};