]> git.lizzy.rs Git - rust.git/commitdiff
Deprecated `str::raw::from_utf8_owned`
authorAdolfo OchagavĂ­a <aochagavia92@gmail.com>
Sat, 19 Jul 2014 10:23:47 +0000 (12:23 +0200)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 24 Jul 2014 14:25:43 +0000 (07:25 -0700)
Replaced by `string::raw::from_utf8`

[breaking-change]

src/libcollections/str.rs
src/libcollections/string.rs
src/libserialize/base64.rs
src/libserialize/hex.rs

index 69372b6d89cf73671f48164b8ecf0f7b4ea7bc91..05107f5dda53a66f58b05651f8ec814eae7230c4 100644 (file)
@@ -559,7 +559,7 @@ pub mod raw {
     use core::raw::Slice;
     use core::ptr::RawPtr;
 
-    use string::String;
+    use string::{mod, String};
     use vec::Vec;
 
     use MutableSeq;
@@ -592,11 +592,10 @@ pub unsafe fn from_c_str(c_string: *const i8) -> String {
         buf
     }
 
-    /// Converts an owned vector of bytes to a new owned string. This assumes
-    /// that the utf-8-ness of the vector has already been validated
-    #[inline]
+    /// Deprecated. Replaced by `string::raw::from_utf8`
+    #[deprecated = "Use string::raw::from_utf8"]
     pub unsafe fn from_utf8_owned(v: Vec<u8>) -> String {
-        mem::transmute(v)
+        string::raw::from_utf8(v)
     }
 
     /// Converts a byte to a string.
index d58dfdd10d131202ed7f200d1321e8167003daea..05321f46b11f6bfe30cc10e8c9ffc7be75ff4d01 100644 (file)
@@ -570,6 +570,19 @@ fn add(&self, other: &S) -> String {
     }
 }
 
+pub mod raw {
+    use super::String;
+    use vec::Vec;
+
+    /// Converts a vector of bytes to a new `String` without checking if
+    /// it contains valid UTF-8. This is unsafe because it assumes that
+    /// the utf-8-ness of the vector has already been validated.
+    #[inline]
+    pub unsafe fn from_utf8(bytes: Vec<u8>) -> String {
+        String { vec: bytes }
+    }
+}
+
 #[cfg(test)]
 mod tests {
     use std::prelude::*;
index 5e8648d355ebfd025fcd35a69d0492a009c2a167..9a30e87647a83b9fb9f28d2dfdaf325789d5467f 100644 (file)
@@ -11,8 +11,8 @@
 // ignore-lexer-test FIXME #15679
 
 //! Base64 binary-to-text encoding
-use std::str;
 use std::fmt;
+use std::string;
 
 /// Available encoding character sets
 pub enum CharacterSet {
@@ -148,7 +148,7 @@ fn to_base64(&self, config: Config) -> String {
         }
 
         unsafe {
-            str::raw::from_utf8_owned(v)
+            string::raw::from_utf8(v)
         }
     }
 }
index d6a029c583cd25e896554f9d1fd9f9c75dc39bcd..fa5b3ca4040d0bb29feedd24cf9279da7189f5df 100644 (file)
@@ -11,8 +11,8 @@
 // ignore-lexer-test FIXME #15679
 
 //! Hex binary-to-text encoding
-use std::str;
 use std::fmt;
+use std::string;
 
 /// A trait for converting a value to hexadecimal encoding
 pub trait ToHex {
@@ -47,7 +47,7 @@ fn to_hex(&self) -> String {
         }
 
         unsafe {
-            str::raw::from_utf8_owned(v)
+            string::raw::from_utf8(v)
         }
     }
 }