about summary refs log tree commit diff
path: root/src/libstd/ffi
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-03-24 17:38:09 +0000
committerbors <bors@rust-lang.org>2015-03-24 17:38:09 +0000
commited810385045ab0db90303574ba3ea47dfa2a36d5 (patch)
tree161242c800aca625a26c56551fa5adb446c0089f /src/libstd/ffi
parent28a0b25f424090255966273994748a9f9901059f (diff)
parentd252d0ad5434bcf77076729ab766eeff98f20ead (diff)
downloadrust-ed810385045ab0db90303574ba3ea47dfa2a36d5.tar.gz
rust-ed810385045ab0db90303574ba3ea47dfa2a36d5.zip
Auto merge of #23654 - alexcrichton:rollup, r=alexcrichton
Diffstat (limited to 'src/libstd/ffi')
-rw-r--r--src/libstd/ffi/c_str.rs17
-rw-r--r--src/libstd/ffi/os_str.rs89
2 files changed, 100 insertions, 6 deletions
diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs
index fc4f03ff3a5..8b19d160172 100644
--- a/src/libstd/ffi/c_str.rs
+++ b/src/libstd/ffi/c_str.rs
@@ -10,6 +10,7 @@
 
 #![unstable(feature = "std_misc")]
 
+use convert::Into;
 use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering};
 use error::{Error, FromError};
 use fmt;
@@ -44,6 +45,7 @@ use vec::Vec;
 /// # Examples
 ///
 /// ```no_run
+/// # #![feature(libc)]
 /// # extern crate libc;
 /// # fn main() {
 /// use std::ffi::CString;
@@ -82,6 +84,7 @@ pub struct CString {
 /// Inspecting a foreign C string
 ///
 /// ```no_run
+/// # #![feature(libc)]
 /// extern crate libc;
 /// use std::ffi::CStr;
 ///
@@ -98,6 +101,7 @@ pub struct CString {
 /// Passing a Rust-originating C string
 ///
 /// ```no_run
+/// # #![feature(libc)]
 /// extern crate libc;
 /// use std::ffi::{CString, CStr};
 ///
@@ -130,6 +134,8 @@ pub struct NulError(usize, Vec<u8>);
 
 /// A conversion trait used by the constructor of `CString` for types that can
 /// be converted to a vector of bytes.
+#[deprecated(since = "1.0.0", reason = "use std::convert::Into<Vec<u8>> instead")]
+#[unstable(feature = "std_misc")]
 pub trait IntoBytes {
     /// Consumes this container, returning a vector of bytes.
     fn into_bytes(self) -> Vec<u8>;
@@ -144,6 +150,7 @@ impl CString {
     /// # Examples
     ///
     /// ```no_run
+    /// # #![feature(libc)]
     /// extern crate libc;
     /// use std::ffi::CString;
     ///
@@ -163,8 +170,8 @@ impl CString {
     /// internal 0 byte. The error returned will contain the bytes as well as
     /// the position of the nul byte.
     #[stable(feature = "rust1", since = "1.0.0")]
-    pub fn new<T: IntoBytes>(t: T) -> Result<CString, NulError> {
-        let bytes = t.into_bytes();
+    pub fn new<T: Into<Vec<u8>>>(t: T) -> Result<CString, NulError> {
+        let bytes = t.into();
         match bytes.iter().position(|x| *x == 0) {
             Some(i) => Err(NulError(i, bytes)),
             None => Ok(unsafe { CString::from_vec_unchecked(bytes) }),
@@ -179,6 +186,7 @@ impl CString {
     /// # Examples
     ///
     /// ```no_run
+    /// # #![feature(libc)]
     /// extern crate libc;
     /// use std::ffi::CString;
     ///
@@ -329,6 +337,7 @@ impl CStr {
     /// # Examples
     ///
     /// ```no_run
+    /// # #![feature(libc)]
     /// # extern crate libc;
     /// # fn main() {
     /// use std::ffi::CStr;
@@ -433,15 +442,19 @@ pub unsafe fn c_str_to_bytes_with_nul<'a>(raw: &'a *const libc::c_char)
     slice::from_raw_parts(*(raw as *const _ as *const *const u8), len as usize)
 }
 
+#[allow(deprecated)]
 impl<'a> IntoBytes for &'a str {
     fn into_bytes(self) -> Vec<u8> { self.as_bytes().to_vec() }
 }
+#[allow(deprecated)]
 impl<'a> IntoBytes for &'a [u8] {
     fn into_bytes(self) -> Vec<u8> { self.to_vec() }
 }
+#[allow(deprecated)]
 impl IntoBytes for String {
     fn into_bytes(self) -> Vec<u8> { self.into_bytes() }
 }
+#[allow(deprecated)]
 impl IntoBytes for Vec<u8> {
     fn into_bytes(self) -> Vec<u8> { self }
 }
diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs
index feacbf1e98b..5851c6e2998 100644
--- a/src/libstd/ffi/os_str.rs
+++ b/src/libstd/ffi/os_str.rs
@@ -63,16 +63,18 @@ pub struct OsStr {
 impl OsString {
     /// Constructs an `OsString` at no cost by consuming a `String`.
     #[stable(feature = "rust1", since = "1.0.0")]
+    #[deprecated(since = "1.0.0", reason = "use `from` instead")]
     pub fn from_string(s: String) -> OsString {
-        OsString { inner: Buf::from_string(s) }
+        OsString::from(s)
     }
 
     /// Constructs an `OsString` by copying from a `&str` slice.
     ///
     /// Equivalent to: `OsString::from_string(String::from_str(s))`.
     #[stable(feature = "rust1", since = "1.0.0")]
+    #[deprecated(since = "1.0.0", reason = "use `from` instead")]
     pub fn from_str(s: &str) -> OsString {
-        OsString { inner: Buf::from_str(s) }
+        OsString::from(s)
     }
 
     /// Constructs a new empty `OsString`.
@@ -98,11 +100,40 @@ impl OsString {
 
     /// Extend the string with the given `&OsStr` slice.
     #[stable(feature = "rust1", since = "1.0.0")]
-    pub fn push<T: AsOsStr + ?Sized>(&mut self, s: &T) {
-        self.inner.push_slice(&s.as_os_str().inner)
+    pub fn push<T: AsRef<OsStr>>(&mut self, s: T) {
+        self.inner.push_slice(&s.as_ref().inner)
+    }
+}
+
+#[stable(feature = "rust1", since = "1.0.0")]
+impl From<String> for OsString {
+    fn from(s: String) -> OsString {
+        OsString { inner: Buf::from_string(s) }
+    }
+}
+
+#[stable(feature = "rust1", since = "1.0.0")]
+impl<'a> From<&'a String> for OsString {
+    fn from(s: &'a String) -> OsString {
+        OsString { inner: Buf::from_str(s) }
+    }
+}
+
+#[stable(feature = "rust1", since = "1.0.0")]
+impl<'a> From<&'a str> for OsString {
+    fn from(s: &'a str) -> OsString {
+        OsString { inner: Buf::from_str(s) }
+    }
+}
+
+#[stable(feature = "rust1", since = "1.0.0")]
+impl<'a> From<&'a OsStr> for OsString {
+    fn from(s: &'a OsStr) -> OsString {
+        OsString { inner: s.inner.to_owned() }
     }
 }
 
+#[cfg(stage0)]
 #[stable(feature = "rust1", since = "1.0.0")]
 impl ops::Index<ops::RangeFull> for OsString {
     type Output = OsStr;
@@ -113,6 +144,17 @@ impl ops::Index<ops::RangeFull> for OsString {
     }
 }
 
+#[cfg(not(stage0))]
+#[stable(feature = "rust1", since = "1.0.0")]
+impl ops::Index<ops::RangeFull> for OsString {
+    type Output = OsStr;
+
+    #[inline]
+    fn index(&self, _index: ops::RangeFull) -> &OsStr {
+        unsafe { mem::transmute(self.inner.as_slice()) }
+    }
+}
+
 #[stable(feature = "rust1", since = "1.0.0")]
 impl ops::Deref for OsString {
     type Target = OsStr;
@@ -316,37 +358,76 @@ impl ToOwned for OsStr {
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
+#[deprecated(since = "1.0.0", reason = "trait is deprecated")]
 impl<'a, T: AsOsStr + ?Sized> AsOsStr for &'a T {
     fn as_os_str(&self) -> &OsStr {
         (*self).as_os_str()
     }
 }
 
+#[stable(feature = "rust1", since = "1.0.0")]
+#[deprecated(since = "1.0.0", reason = "trait is deprecated")]
 impl AsOsStr for OsStr {
     fn as_os_str(&self) -> &OsStr {
         self
     }
 }
 
+#[stable(feature = "rust1", since = "1.0.0")]
+#[deprecated(since = "1.0.0", reason = "trait is deprecated")]
 impl AsOsStr for OsString {
     fn as_os_str(&self) -> &OsStr {
         &self[..]
     }
 }
 
+#[stable(feature = "rust1", since = "1.0.0")]
+#[deprecated(since = "1.0.0", reason = "trait is deprecated")]
 impl AsOsStr for str {
     fn as_os_str(&self) -> &OsStr {
         OsStr::from_str(self)
     }
 }
 
+#[stable(feature = "rust1", since = "1.0.0")]
+#[deprecated(since = "1.0.0", reason = "trait is deprecated")]
 impl AsOsStr for String {
     fn as_os_str(&self) -> &OsStr {
         OsStr::from_str(&self[..])
     }
 }
 
+#[stable(feature = "rust1", since = "1.0.0")]
+impl AsRef<OsStr> for OsStr {
+    fn as_ref(&self) -> &OsStr {
+        self
+    }
+}
+
+#[stable(feature = "rust1", since = "1.0.0")]
+impl AsRef<OsStr> for OsString {
+    fn as_ref(&self) -> &OsStr {
+        self
+    }
+}
+
+#[stable(feature = "rust1", since = "1.0.0")]
+impl AsRef<OsStr> for str {
+    fn as_ref(&self) -> &OsStr {
+        OsStr::from_str(self)
+    }
+}
+
+#[stable(feature = "rust1", since = "1.0.0")]
+impl AsRef<OsStr> for String {
+    fn as_ref(&self) -> &OsStr {
+        OsStr::from_str(&self[..])
+    }
+}
+
 #[allow(deprecated)]
+#[stable(feature = "rust1", since = "1.0.0")]
+#[deprecated(since = "1.0.0", reason = "trait is deprecated")]
 impl AsOsStr for Path {
     #[cfg(unix)]
     fn as_os_str(&self) -> &OsStr {