From 0fe894e49be235ff0ac22231d7fa3579a4192f0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20Ochagav=C3=ADa?= Date: Mon, 21 Jul 2014 20:44:56 +0200 Subject: [PATCH] Deprecated `String::from_raw_parts` Replaced by `string::raw::from_parts` [breaking-change] --- src/libcollections/str.rs | 3 ++- src/libcollections/string.rs | 27 +++++++++++++++++++-------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index 731c761351c2..db859bbf5bf3 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -558,7 +558,8 @@ pub mod raw { use core::mem; use core::raw::Slice; use core::ptr::RawPtr; - use string::{mod, String}; + use string; + use string::String; use vec::Vec; use MutableSeq; diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index bb8424bd3633..aeb323a9caf9 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -49,14 +49,6 @@ impl String { } } - /// Creates a new string buffer from length, capacity, and a pointer. - #[inline] - pub unsafe fn from_raw_parts(length: uint, capacity: uint, ptr: *mut u8) -> String { - String { - vec: Vec::from_raw_parts(length, capacity, ptr), - } - } - /// Creates a new string buffer from the given string. #[inline] pub fn from_str(string: &str) -> String { @@ -65,6 +57,13 @@ impl String { } } + /// Deprecated. Replaced by `string::raw::from_parts` + #[inline] + #[deprecated = "Replaced by string::raw::from_parts"] + pub unsafe fn from_raw_parts(length: uint, capacity: uint, ptr: *mut u8) -> String { + raw::from_parts(length, capacity, ptr) + } + #[allow(missing_doc)] #[deprecated = "obsoleted by the removal of ~str"] #[inline] @@ -577,6 +576,18 @@ pub mod raw { use super::String; use vec::Vec; + /// Creates a new `String` from length, capacity, and a pointer. + /// + /// This is unsafe because: + /// * We call `Vec::from_raw_parts` to get a `Vec` + /// * We assume that the `Vec` contains valid UTF-8 + #[inline] + pub unsafe fn from_parts(length: uint, capacity: uint, ptr: *mut u8) -> String { + String { + vec: Vec::from_raw_parts(length, capacity, ptr), + } + } + /// 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.