Skip to content

Commit ed2c99b

Browse files
committed
Deprecated String::from_raw_parts
Replaced by `string::raw::from_parts` [breaking-change]
1 parent f8cd834 commit ed2c99b

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

src/libcollections/str.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,8 @@ pub mod raw {
558558
use core::mem;
559559
use core::raw::Slice;
560560
use core::ptr::RawPtr;
561-
use string::{mod, String};
561+
use string;
562+
use string::String;
562563
use vec::Vec;
563564

564565
pub use core::str::raw::{from_utf8, c_str_to_static_slice, slice_bytes};

src/libcollections/string.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,6 @@ impl String {
4949
}
5050
}
5151

52-
/// Creates a new string buffer from length, capacity, and a pointer.
53-
#[inline]
54-
pub unsafe fn from_raw_parts(length: uint, capacity: uint, ptr: *mut u8) -> String {
55-
String {
56-
vec: Vec::from_raw_parts(length, capacity, ptr),
57-
}
58-
}
59-
6052
/// Creates a new string buffer from the given string.
6153
#[inline]
6254
pub fn from_str(string: &str) -> String {
@@ -65,6 +57,13 @@ impl String {
6557
}
6658
}
6759

60+
/// Deprecated. Replaced by `string::raw::from_parts`
61+
#[inline]
62+
#[deprecated = "Replaced by string::raw::from_parts"]
63+
pub unsafe fn from_raw_parts(length: uint, capacity: uint, ptr: *mut u8) -> String {
64+
raw::from_parts(length, capacity, ptr)
65+
}
66+
6867
#[allow(missing_doc)]
6968
#[deprecated = "obsoleted by the removal of ~str"]
7069
#[inline]
@@ -577,6 +576,18 @@ pub mod raw {
577576
use super::String;
578577
use vec::Vec;
579578

579+
/// Creates a new `String` from length, capacity, and a pointer.
580+
///
581+
/// This is unsafe because:
582+
/// * We call `Vec::from_raw_parts` to get a `Vec<u8>`
583+
/// * We assume that the `Vec` contains valid UTF-8
584+
#[inline]
585+
pub unsafe fn from_parts(length: uint, capacity: uint, ptr: *mut u8) -> String {
586+
String {
587+
vec: Vec::from_raw_parts(length, capacity, ptr),
588+
}
589+
}
590+
580591
/// Converts a vector of bytes to a new `String` without checking if
581592
/// it contains valid UTF-8. This is unsafe because it assumes that
582593
/// the utf-8-ness of the vector has already been validated.

0 commit comments

Comments
 (0)