Skip to content

Commit 5c6d1c8

Browse files
committed
Deprecated str::raw::from_utf8_owned
Replaced by `string::raw::from_utf8` [breaking-change]
1 parent 1a4b888 commit 5c6d1c8

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

src/libcollections/str.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ pub mod raw {
559559
use core::raw::Slice;
560560
use core::ptr::RawPtr;
561561

562-
use string::String;
562+
use string::{mod, String};
563563
use vec::Vec;
564564

565565
pub use core::str::raw::{from_utf8, c_str_to_static_slice, slice_bytes};
@@ -590,11 +590,10 @@ pub mod raw {
590590
buf
591591
}
592592

593-
/// Converts an owned vector of bytes to a new owned string. This assumes
594-
/// that the utf-8-ness of the vector has already been validated
595-
#[inline]
593+
/// Deprecated. Replaced by `string::raw::from_utf8`
594+
#[deprecated = "Use string::raw::from_utf8"]
596595
pub unsafe fn from_utf8_owned(v: Vec<u8>) -> String {
597-
mem::transmute(v)
596+
string::raw::from_utf8(v)
598597
}
599598

600599
/// Converts a byte to a string.

src/libcollections/string.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,19 @@ impl<S: Str> Add<S, String> for String {
570570
}
571571
}
572572

573+
pub mod raw {
574+
use super::String;
575+
use vec::Vec;
576+
577+
/// Converts a vector of bytes to a new `String` without checking if
578+
/// it contains valid UTF-8. This is unsafe because it assumes that
579+
/// the utf-8-ness of the vector has already been validated.
580+
#[inline]
581+
pub unsafe fn from_utf8(bytes: Vec<u8>) -> String {
582+
String { vec: bytes }
583+
}
584+
}
585+
573586
#[cfg(test)]
574587
mod tests {
575588
use std::prelude::*;

src/libserialize/base64.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
// ignore-lexer-test FIXME #15679
1212

1313
//! Base64 binary-to-text encoding
14-
use std::str;
1514
use std::fmt;
15+
use std::string;
1616

1717
/// Available encoding character sets
1818
pub enum CharacterSet {
@@ -148,7 +148,7 @@ impl<'a> ToBase64 for &'a [u8] {
148148
}
149149

150150
unsafe {
151-
str::raw::from_utf8_owned(v)
151+
string::raw::from_utf8(v)
152152
}
153153
}
154154
}

src/libserialize/hex.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
// ignore-lexer-test FIXME #15679
1212

1313
//! Hex binary-to-text encoding
14-
use std::str;
1514
use std::fmt;
15+
use std::string;
1616

1717
/// A trait for converting a value to hexadecimal encoding
1818
pub trait ToHex {
@@ -47,7 +47,7 @@ impl<'a> ToHex for &'a [u8] {
4747
}
4848

4949
unsafe {
50-
str::raw::from_utf8_owned(v)
50+
string::raw::from_utf8(v)
5151
}
5252
}
5353
}

0 commit comments

Comments
 (0)