提交 9ec19373 编写于 作者: A Adolfo Ochagavía 提交者: Alex Crichton

Deprecated `str::raw::from_utf8_owned`

Replaced by `string::raw::from_utf8`

[breaking-change]
上级 eacc5d77
......@@ -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.
......
......@@ -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::*;
......
......@@ -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)
}
}
}
......
......@@ -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)
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册