Skip to content

Commit bec6409

Browse files
committed
Rename String::into_boxed_slice -> into_boxed_str
This is the name that was decided in rust-lang/rfcs#1152, and it's better if we say “boxed str” for `Box<str>`. The old name `String::into_boxed_slice` is deprecated.
1 parent f50518e commit bec6409

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/libcollections/string.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -749,10 +749,20 @@ impl String {
749749
/// Note that this will drop any excess capacity.
750750
#[unstable(feature = "box_str",
751751
reason = "recently added, matches RFC")]
752-
pub fn into_boxed_slice(self) -> Box<str> {
752+
pub fn into_boxed_str(self) -> Box<str> {
753753
let slice = self.vec.into_boxed_slice();
754754
unsafe { mem::transmute::<Box<[u8]>, Box<str>>(slice) }
755755
}
756+
757+
/// Converts the string into `Box<str>`.
758+
///
759+
/// Note that this will drop any excess capacity.
760+
#[unstable(feature = "box_str",
761+
reason = "recently added, matches RFC")]
762+
#[deprecated(since = "1.4.0", reason = "renamed to `into_boxed_str`")]
763+
pub fn into_boxed_slice(self) -> Box<str> {
764+
self.into_boxed_str()
765+
}
756766
}
757767

758768
impl FromUtf8Error {

src/libcollectionstest/str.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1763,13 +1763,13 @@ fn test_into_string() {
17631763
// The only way to acquire a Box<str> in the first place is through a String, so just
17641764
// test that we can round-trip between Box<str> and String.
17651765
let string = String::from("Some text goes here");
1766-
assert_eq!(string.clone().into_boxed_slice().into_string(), string);
1766+
assert_eq!(string.clone().into_boxed_str().into_string(), string);
17671767
}
17681768

17691769
#[test]
17701770
fn test_box_slice_clone() {
17711771
let data = String::from("hello HELLO hello HELLO yes YES 5 中ä华!!!");
1772-
let data2 = data.clone().into_boxed_slice().clone().into_string();
1772+
let data2 = data.clone().into_boxed_str().clone().into_string();
17731773

17741774
assert_eq!(data, data2);
17751775
}

src/libcollectionstest/string.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,9 @@ fn test_extend_ref() {
366366
}
367367

368368
#[test]
369-
fn test_into_boxed_slice() {
369+
fn test_into_boxed_str() {
370370
let xs = String::from("hello my name is bob");
371-
let ys = xs.into_boxed_slice();
371+
let ys = xs.into_boxed_str();
372372
assert_eq!(&*ys, "hello my name is bob");
373373
}
374374

0 commit comments

Comments
 (0)