Skip to content

Commit

Permalink
Add std::ffi::c_str module
Browse files Browse the repository at this point in the history
  • Loading branch information
clarfonthey committed Jul 1, 2023
1 parent 6162f6f commit 3baf19f
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 11 deletions.
2 changes: 2 additions & 0 deletions library/alloc/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! [`CString`] and its related types.

#[cfg(test)]
mod tests;

Expand Down
10 changes: 7 additions & 3 deletions library/alloc/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,13 @@

#![stable(feature = "alloc_ffi", since = "1.64.0")]

#[doc(no_inline)]
#[stable(feature = "alloc_c_string", since = "1.64.0")]
pub use self::c_str::FromVecWithNulError;
pub use self::c_str::{FromVecWithNulError, IntoStringError, NulError};

#[doc(inline)]
#[stable(feature = "alloc_c_string", since = "1.64.0")]
pub use self::c_str::{CString, IntoStringError, NulError};
pub use self::c_str::CString;

mod c_str;
#[unstable(feature = "c_str_module", issue = "112134")]
pub mod c_str;
6 changes: 4 additions & 2 deletions library/core/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! [`CStr`] and its related types.

use crate::cmp::Ordering;
use crate::error::Error;
use crate::ffi::c_char;
Expand Down Expand Up @@ -25,8 +27,8 @@ use crate::str;
/// functions may leverage the unsafe [`CStr::from_ptr`] constructor to provide
/// a safe interface to other consumers.
///
/// [`CString`]: ../../std/ffi/struct.CString.html
/// [`String`]: ../../std/string/struct.String.html
/// [`CString`]: ../../../std/ffi/c_str/struct.CString.html
/// [`String`]: ../../../std/string/struct.String.html
///
/// # Examples
///
Expand Down
14 changes: 12 additions & 2 deletions library/core/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,20 @@ use crate::marker::PhantomData;
use crate::num::*;
use crate::ops::{Deref, DerefMut};

#[doc(no_inline)]
#[stable(feature = "core_c_str", since = "1.64.0")]
pub use self::c_str::{CStr, FromBytesUntilNulError, FromBytesWithNulError};
pub use self::c_str::FromBytesWithNulError;

mod c_str;
#[doc(no_inline)]
#[stable(feature = "cstr_from_bytes_until_nul", since = "1.69.0")]
pub use self::c_str::FromBytesUntilNulError;

#[doc(inline)]
#[stable(feature = "core_c_str", since = "1.64.0")]
pub use self::c_str::CStr;

#[unstable(feature = "c_str_module", issue = "112134")]
pub mod c_str;

macro_rules! type_alias_no_nz {
{
Expand Down
19 changes: 19 additions & 0 deletions library/std/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//! [`CStr`], [`CString`], and related types.

#[stable(feature = "rust1", since = "1.0.0")]
pub use core::ffi::c_str::CStr;

#[stable(feature = "cstr_from_bytes", since = "1.10.0")]
pub use core::ffi::c_str::FromBytesWithNulError;

#[stable(feature = "cstr_from_bytes_until_nul", since = "1.69.0")]
pub use core::ffi::c_str::FromBytesUntilNulError;

#[stable(feature = "rust1", since = "1.0.0")]
pub use alloc::ffi::c_str::{CString, NulError};

#[stable(feature = "cstring_from_vec_with_nul", since = "1.58.0")]
pub use alloc::ffi::c_str::FromVecWithNulError;

#[stable(feature = "cstring_into", since = "1.7.0")]
pub use alloc::ffi::c_str::IntoStringError;
30 changes: 26 additions & 4 deletions library/std/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,32 @@

#![stable(feature = "rust1", since = "1.0.0")]

#[stable(feature = "alloc_c_string", since = "1.64.0")]
pub use alloc::ffi::{CString, FromVecWithNulError, IntoStringError, NulError};
#[stable(feature = "core_c_str", since = "1.64.0")]
pub use core::ffi::{CStr, FromBytesWithNulError};
#[unstable(feature = "c_str_module", issue = "112134")]
pub mod c_str;

#[doc(inline)]
#[stable(feature = "rust1", since = "1.0.0")]
pub use self::c_str::{CStr, CString};

#[doc(no_inline)]
#[stable(feature = "cstr_from_bytes", since = "1.10.0")]
pub use self::c_str::FromBytesWithNulError;

#[doc(no_inline)]
#[stable(feature = "cstr_from_bytes_until_nul", since = "1.69.0")]
pub use self::c_str::FromBytesUntilNulError;

#[doc(no_inline)]
#[stable(feature = "rust1", since = "1.0.0")]
pub use self::c_str::NulError;

#[doc(no_inline)]
#[stable(feature = "cstring_from_vec_with_nul", since = "1.58.0")]
pub use self::c_str::FromVecWithNulError;

#[doc(no_inline)]
#[stable(feature = "cstring_into", since = "1.7.0")]
pub use self::c_str::IntoStringError;

#[stable(feature = "rust1", since = "1.0.0")]
pub use self::os_str::{OsStr, OsString};
Expand Down
1 change: 1 addition & 0 deletions library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@
//
// Library features (core):
// tidy-alphabetical-start
#![feature(c_str_module)]
#![feature(char_internals)]
#![feature(core_intrinsics)]
#![feature(duration_constants)]
Expand Down

0 comments on commit 3baf19f

Please sign in to comment.