From 9ec19373af8aaad641b39a25fa4ac7bfef513fc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20Ochagav=C3=ADa?= Date: Sat, 19 Jul 2014 12:23:47 +0200 Subject: [PATCH] Deprecated `str::raw::from_utf8_owned` Replaced by `string::raw::from_utf8` [breaking-change] --- src/libcollections/str.rs | 9 ++++----- src/libcollections/string.rs | 13 +++++++++++++ src/libserialize/base64.rs | 4 ++-- 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 69372b6d89cf..05107f5dda53 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) -> 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 d58dfdd10d13..05321f46b11f 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -570,6 +570,19 @@ impl Add 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) -> String { + String { vec: bytes } + } +} + #[cfg(test)] mod tests { use std::prelude::*; diff --git a/src/libserialize/base64.rs b/src/libserialize/base64.rs index 5e8648d355eb..9a30e87647a8 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 d6a029c583cd..fa5b3ca4040d 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) } } }