Skip to content

Commit d83ba75

Browse files
committed
Auto merge of #27696 - bluss:into-boxed-str, r=alexcrichton
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.
2 parents 7b7fc67 + bec6409 commit d83ba75

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
@@ -747,10 +747,20 @@ impl String {
747747
/// Note that this will drop any excess capacity.
748748
#[unstable(feature = "box_str",
749749
reason = "recently added, matches RFC")]
750-
pub fn into_boxed_slice(self) -> Box<str> {
750+
pub fn into_boxed_str(self) -> Box<str> {
751751
let slice = self.vec.into_boxed_slice();
752752
unsafe { mem::transmute::<Box<[u8]>, Box<str>>(slice) }
753753
}
754+
755+
/// Converts the string into `Box<str>`.
756+
///
757+
/// Note that this will drop any excess capacity.
758+
#[unstable(feature = "box_str",
759+
reason = "recently added, matches RFC")]
760+
#[deprecated(since = "1.4.0", reason = "renamed to `into_boxed_str`")]
761+
pub fn into_boxed_slice(self) -> Box<str> {
762+
self.into_boxed_str()
763+
}
754764
}
755765

756766
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)