about summary refs log tree commit diff
path: root/src/libstd/ffi
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2015-09-09 22:37:59 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2015-09-09 22:37:59 +0300
commit104902100d8894d7578694754590668d6d725a17 (patch)
tree283a1e8614e4d460fa4f9848ce81f096d17753ad /src/libstd/ffi
parent0762f58c1143b4ff0ae5d0cdda9cdd8249512e77 (diff)
downloadrust-104902100d8894d7578694754590668d6d725a17.tar.gz
rust-104902100d8894d7578694754590668d6d725a17.zip
Reduce code bloat from conversion traits in function parameters
Diffstat (limited to 'src/libstd/ffi')
-rw-r--r--src/libstd/ffi/c_str.rs5
-rw-r--r--src/libstd/ffi/os_str.rs20
2 files changed, 14 insertions, 11 deletions
diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs
index 23daa87401a..6181c6c4ca6 100644
--- a/src/libstd/ffi/c_str.rs
+++ b/src/libstd/ffi/c_str.rs
@@ -181,7 +181,10 @@ impl CString {
     /// the position of the nul byte.
     #[stable(feature = "rust1", since = "1.0.0")]
     pub fn new<T: Into<Vec<u8>>>(t: T) -> Result<CString, NulError> {
-        let bytes = t.into();
+        Self::_new(t.into())
+    }
+
+    fn _new(bytes: Vec<u8>) -> Result<CString, NulError> {
         match bytes.iter().position(|x| *x == 0) {
             Some(i) => Err(NulError(i, bytes)),
             None => Ok(unsafe { CString::from_vec_unchecked(bytes) }),
diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs
index 751c76b9960..7409d9b45d2 100644
--- a/src/libstd/ffi/os_str.rs
+++ b/src/libstd/ffi/os_str.rs
@@ -73,18 +73,18 @@ impl OsString {
     /// convert; non UTF-8 data will produce `None`.
     #[unstable(feature = "convert", reason = "recently added", issue = "27704")]
     pub fn from_bytes<B>(bytes: B) -> Option<OsString> where B: Into<Vec<u8>> {
-        #[cfg(unix)]
-        fn from_bytes_inner(vec: Vec<u8>) -> Option<OsString> {
-            use os::unix::ffi::OsStringExt;
-            Some(OsString::from_vec(vec))
-        }
+        Self::_from_bytes(bytes.into())
+    }
 
-        #[cfg(windows)]
-        fn from_bytes_inner(vec: Vec<u8>) -> Option<OsString> {
-            String::from_utf8(vec).ok().map(OsString::from)
-        }
+    #[cfg(unix)]
+    fn _from_bytes(vec: Vec<u8>) -> Option<OsString> {
+        use os::unix::ffi::OsStringExt;
+        Some(OsString::from_vec(vec))
+    }
 
-        from_bytes_inner(bytes.into())
+    #[cfg(windows)]
+    fn _from_bytes(vec: Vec<u8>) -> Option<OsString> {
+        String::from_utf8(vec).ok().map(OsString::from)
     }
 
     /// Converts to an `OsStr` slice.