From 8ca27a633ed393438a12bbf074b4f2e6063baa6f Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 20 Nov 2014 10:11:15 -0800 Subject: std: Align `raw` modules with unsafe conventions This commit is an implementation of [RFC 240][rfc] when applied to the standard library. It primarily deprecates the entirety of `string::raw`, `vec::raw`, `slice::raw`, and `str::raw` in favor of associated functions, methods, and other free functions. The detailed renaming is: * slice::raw::buf_as_slice => slice::with_raw_buf * slice::raw::mut_buf_as_slice => slice::with_raw_mut_buf * slice::shift_ptr => deprecated with no replacement * slice::pop_ptr => deprecated with no replacement * str::raw::from_utf8 => str::from_utf8_unchecked * str::raw::c_str_to_static_slice => str::from_c_str * str::raw::slice_bytes => deprecated for slice_unchecked (slight semantic diff) * str::raw::slice_unchecked => str.slice_unchecked * string::raw::from_parts => String::from_raw_parts * string::raw::from_buf_len => String::from_raw_buf_len * string::raw::from_buf => String::from_raw_buf * string::raw::from_utf8 => String::from_utf8_unchecked * vec::raw::from_buf => Vec::from_raw_buf All previous functions exist in their `#[deprecated]` form, and the deprecation messages indicate how to migrate to the newer variants. [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/0240-unsafe-api-location.md [breaking-change] Closes #17863 --- src/libserialize/base64.rs | 9 +++------ src/libserialize/hex.rs | 5 ++--- 2 files changed, 5 insertions(+), 9 deletions(-) (limited to 'src/libserialize') diff --git a/src/libserialize/base64.rs b/src/libserialize/base64.rs index 9b1e285431f..41feee8257f 100644 --- a/src/libserialize/base64.rs +++ b/src/libserialize/base64.rs @@ -16,7 +16,6 @@ pub use self::FromBase64Error::*; pub use self::CharacterSet::*; use std::fmt; -use std::string; use std::error; /// Available encoding character sets @@ -152,9 +151,7 @@ impl ToBase64 for [u8] { _ => panic!("Algebra is broken, please alert the math police") } - unsafe { - string::raw::from_utf8(v) - } + unsafe { String::from_utf8_unchecked(v) } } } @@ -201,8 +198,8 @@ impl FromBase64 for str { * Convert any base64 encoded string (literal, `@`, `&`, or `~`) * to the byte values it encodes. * - * You can use the `String::from_utf8` function in `std::string` to turn a - * `Vec` into a string with characters corresponding to those values. + * You can use the `String::from_utf8` function to turn a `Vec` into a + * string with characters corresponding to those values. * * # Example * diff --git a/src/libserialize/hex.rs b/src/libserialize/hex.rs index bd49da7667a..78859d6778d 100644 --- a/src/libserialize/hex.rs +++ b/src/libserialize/hex.rs @@ -15,7 +15,6 @@ pub use self::FromHexError::*; use std::fmt; -use std::string; use std::error; /// A trait for converting a value to hexadecimal encoding @@ -51,7 +50,7 @@ impl ToHex for [u8] { } unsafe { - string::raw::from_utf8(v) + String::from_utf8_unchecked(v) } } } @@ -100,7 +99,7 @@ impl FromHex for str { * Convert any hexadecimal encoded string (literal, `@`, `&`, or `~`) * to the byte values it encodes. * - * You can use the `String::from_utf8` function in `std::string` to turn a + * You can use the `String::from_utf8` function to turn a * `Vec` into a string with characters corresponding to those values. * * # Example -- cgit 1.4.1-3-g733a5