diff options
| author | Adolfo OchagavĂa <aochagavia92@gmail.com> | 2014-07-19 12:23:47 +0200 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-07-24 07:25:43 -0700 |
| commit | 9ec19373af8aaad641b39a25fa4ac7bfef513fc2 (patch) | |
| tree | d0e0ead461f046d85a02ae61387fade1a02944ce /src | |
| parent | eacc5d779fe4080dd2b45e035ca2af099b8b906d (diff) | |
Deprecated `str::raw::from_utf8_owned`
Replaced by `string::raw::from_utf8` [breaking-change]
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcollections/str.rs | 9 | ||||
| -rw-r--r-- | src/libcollections/string.rs | 13 | ||||
| -rw-r--r-- | src/libserialize/base64.rs | 4 | ||||
| -rw-r--r-- | src/libserialize/hex.rs | 4 |
4 files changed, 21 insertions, 9 deletions
diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index 69372b6d89c..05107f5dda5 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -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 mod raw { 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. diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index d58dfdd10d1..05321f46b11 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -570,6 +570,19 @@ impl<S: Str> Add<S, String> for 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::*; diff --git a/src/libserialize/base64.rs b/src/libserialize/base64.rs index 5e8648d355e..9a30e87647a 100644 --- a/src/libserialize/base64.rs +++ b/src/libserialize/base64.rs @@ -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 @@ impl<'a> ToBase64 for &'a [u8] { } unsafe { - str::raw::from_utf8_owned(v) + string::raw::from_utf8(v) } } } diff --git a/src/libserialize/hex.rs b/src/libserialize/hex.rs index d6a029c583c..fa5b3ca4040 100644 --- a/src/libserialize/hex.rs +++ b/src/libserialize/hex.rs @@ -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 @@ impl<'a> ToHex for &'a [u8] { } unsafe { - str::raw::from_utf8_owned(v) + string::raw::from_utf8(v) } } } |
