about summary refs log tree commit diff
path: root/src/libstd/ffi
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2016-05-17 11:57:07 -0700
committerAlex Crichton <alex@alexcrichton.com>2016-05-24 09:00:39 -0700
commitcae91d7c8c21aa860bda29c62207a6726837952b (patch)
tree3c1a8d50e4fded7eaa1830188b013d3d5f998100 /src/libstd/ffi
parent30422de32d905dca54e503ec7990c4d7d11334da (diff)
downloadrust-cae91d7c8c21aa860bda29c62207a6726837952b.tar.gz
rust-cae91d7c8c21aa860bda29c62207a6726837952b.zip
std: Stabilize APIs for the 1.10 release
This commit applies the FCP decisions made by the libs team for the 1.10 cycle,
including both new stabilizations and deprecations. Specifically, the list of
APIs is:

Stabilized:

* `os::windows::fs::OpenOptionsExt::access_mode`
* `os::windows::fs::OpenOptionsExt::share_mode`
* `os::windows::fs::OpenOptionsExt::custom_flags`
* `os::windows::fs::OpenOptionsExt::attributes`
* `os::windows::fs::OpenOptionsExt::security_qos_flags`
* `os::unix::fs::OpenOptionsExt::custom_flags`
* `sync::Weak::new`
* `Default for sync::Weak`
* `panic::set_hook`
* `panic::take_hook`
* `panic::PanicInfo`
* `panic::PanicInfo::payload`
* `panic::PanicInfo::location`
* `panic::Location`
* `panic::Location::file`
* `panic::Location::line`
* `ffi::CStr::from_bytes_with_nul`
* `ffi::CStr::from_bytes_with_nul_unchecked`
* `ffi::FromBytesWithNulError`
* `fs::Metadata::modified`
* `fs::Metadata::accessed`
* `fs::Metadata::created`
* `sync::atomic::Atomic{Usize,Isize,Bool,Ptr}::compare_exchange`
* `sync::atomic::Atomic{Usize,Isize,Bool,Ptr}::compare_exchange_weak`
* `collections::{btree,hash}_map::{Occupied,Vacant,}Entry::key`
* `os::unix::net::{UnixStream, UnixListener, UnixDatagram, SocketAddr}`
* `SocketAddr::is_unnamed`
* `SocketAddr::as_pathname`
* `UnixStream::connect`
* `UnixStream::pair`
* `UnixStream::try_clone`
* `UnixStream::local_addr`
* `UnixStream::peer_addr`
* `UnixStream::set_read_timeout`
* `UnixStream::set_write_timeout`
* `UnixStream::read_timeout`
* `UnixStream::write_Timeout`
* `UnixStream::set_nonblocking`
* `UnixStream::take_error`
* `UnixStream::shutdown`
* Read/Write/RawFd impls for `UnixStream`
* `UnixListener::bind`
* `UnixListener::accept`
* `UnixListener::try_clone`
* `UnixListener::local_addr`
* `UnixListener::set_nonblocking`
* `UnixListener::take_error`
* `UnixListener::incoming`
* RawFd impls for `UnixListener`
* `UnixDatagram::bind`
* `UnixDatagram::unbound`
* `UnixDatagram::pair`
* `UnixDatagram::connect`
* `UnixDatagram::try_clone`
* `UnixDatagram::local_addr`
* `UnixDatagram::peer_addr`
* `UnixDatagram::recv_from`
* `UnixDatagram::recv`
* `UnixDatagram::send_to`
* `UnixDatagram::send`
* `UnixDatagram::set_read_timeout`
* `UnixDatagram::set_write_timeout`
* `UnixDatagram::read_timeout`
* `UnixDatagram::write_timeout`
* `UnixDatagram::set_nonblocking`
* `UnixDatagram::take_error`
* `UnixDatagram::shutdown`
* RawFd impls for `UnixDatagram`
* `{BTree,Hash}Map::values_mut`
* `<[_]>::binary_search_by_key`

Deprecated:

* `StaticCondvar` - this, and all other static synchronization primitives
                    below, are usable today through the lazy-static crate on
                    stable Rust today. Additionally, we'd like the non-static
                    versions to be directly usable in a static context one day,
                    so they're unlikely to be the final forms of the APIs in any
                    case.
* `CONDVAR_INIT`
* `StaticMutex`
* `MUTEX_INIT`
* `StaticRwLock`
* `RWLOCK_INIT`
* `iter::Peekable::is_empty`

Closes #27717
Closes #27720
cc #27784 (but encode methods still exist)
Closes #30014
Closes #30425
Closes #30449
Closes #31190
Closes #31399
Closes #31767
Closes #32111
Closes #32281
Closes #32312
Closes #32551
Closes #33018
Diffstat (limited to 'src/libstd/ffi')
-rw-r--r--src/libstd/ffi/c_str.rs37
-rw-r--r--src/libstd/ffi/mod.rs2
2 files changed, 22 insertions, 17 deletions
diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs
index fbc8886ce8f..2bc7585f5fb 100644
--- a/src/libstd/ffi/c_str.rs
+++ b/src/libstd/ffi/c_str.rs
@@ -159,6 +159,12 @@ pub struct CStr {
 #[stable(feature = "rust1", since = "1.0.0")]
 pub struct NulError(usize, Vec<u8>);
 
+/// An error returned from `CStr::from_bytes_with_nul` to indicate that a nul
+/// byte was found too early in the slice provided or one wasn't found at all.
+#[derive(Clone, PartialEq, Debug)]
+#[stable(feature = "cstr_from_bytes", since = "1.10.0")]
+pub struct FromBytesWithNulError { _a: () }
+
 /// An error returned from `CString::into_string` to indicate that a UTF-8 error
 /// was encountered during the conversion.
 #[derive(Clone, PartialEq, Debug)]
@@ -461,20 +467,18 @@ impl CStr {
     /// # Examples
     ///
     /// ```
-    /// # #![feature(cstr_from_bytes)]
     /// use std::ffi::CStr;
     ///
-    /// # fn main() {
     /// let cstr = CStr::from_bytes_with_nul(b"hello\0");
-    /// assert!(cstr.is_some());
-    /// # }
+    /// assert!(cstr.is_ok());
     /// ```
-    #[unstable(feature = "cstr_from_bytes", reason = "recently added", issue = "31190")]
-    pub fn from_bytes_with_nul(bytes: &[u8]) -> Option<&CStr> {
+    #[stable(feature = "cstr_from_bytes", since = "1.10.0")]
+    pub fn from_bytes_with_nul(bytes: &[u8])
+                               -> Result<&CStr, FromBytesWithNulError> {
         if bytes.is_empty() || memchr::memchr(0, &bytes) != Some(bytes.len() - 1) {
-            None
+            Err(FromBytesWithNulError { _a: () })
         } else {
-            Some(unsafe { Self::from_bytes_with_nul_unchecked(bytes) })
+            Ok(unsafe { Self::from_bytes_with_nul_unchecked(bytes) })
         }
     }
 
@@ -487,18 +491,15 @@ impl CStr {
     /// # Examples
     ///
     /// ```
-    /// # #![feature(cstr_from_bytes)]
     /// use std::ffi::{CStr, CString};
     ///
-    /// # fn main() {
     /// unsafe {
     ///     let cstring = CString::new("hello").unwrap();
     ///     let cstr = CStr::from_bytes_with_nul_unchecked(cstring.to_bytes_with_nul());
     ///     assert_eq!(cstr, &*cstring);
     /// }
-    /// # }
     /// ```
-    #[unstable(feature = "cstr_from_bytes", reason = "recently added", issue = "31190")]
+    #[stable(feature = "cstr_from_bytes", since = "1.10.0")]
     pub unsafe fn from_bytes_with_nul_unchecked(bytes: &[u8]) -> &CStr {
         mem::transmute(bytes)
     }
@@ -742,12 +743,14 @@ mod tests {
     fn from_bytes_with_nul() {
         let data = b"123\0";
         let cstr = CStr::from_bytes_with_nul(data);
-        assert_eq!(cstr.map(CStr::to_bytes), Some(&b"123"[..]));
-        assert_eq!(cstr.map(CStr::to_bytes_with_nul), Some(&b"123\0"[..]));
+        assert_eq!(cstr.map(CStr::to_bytes), Ok(&b"123"[..]));
+        let cstr = CStr::from_bytes_with_nul(data);
+        assert_eq!(cstr.map(CStr::to_bytes_with_nul), Ok(&b"123\0"[..]));
 
         unsafe {
+            let cstr = CStr::from_bytes_with_nul(data);
             let cstr_unchecked = CStr::from_bytes_with_nul_unchecked(data);
-            assert_eq!(cstr, Some(cstr_unchecked));
+            assert_eq!(cstr, Ok(cstr_unchecked));
         }
     }
 
@@ -755,13 +758,13 @@ mod tests {
     fn from_bytes_with_nul_unterminated() {
         let data = b"123";
         let cstr = CStr::from_bytes_with_nul(data);
-        assert!(cstr.is_none());
+        assert!(cstr.is_err());
     }
 
     #[test]
     fn from_bytes_with_nul_interior() {
         let data = b"1\023\0";
         let cstr = CStr::from_bytes_with_nul(data);
-        assert!(cstr.is_none());
+        assert!(cstr.is_err());
     }
 }
diff --git a/src/libstd/ffi/mod.rs b/src/libstd/ffi/mod.rs
index bfd6ab52289..ca1ff18f1ca 100644
--- a/src/libstd/ffi/mod.rs
+++ b/src/libstd/ffi/mod.rs
@@ -14,6 +14,8 @@
 
 #[stable(feature = "rust1", since = "1.0.0")]
 pub use self::c_str::{CString, CStr, NulError, IntoStringError};
+#[stable(feature = "cstr_from_bytes", since = "1.10.0")]
+pub use self::c_str::{FromBytesWithNulError};
 
 #[stable(feature = "rust1", since = "1.0.0")]
 pub use self::os_str::{OsString, OsStr};