Skip to content

Commit e2bebf3

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 82b8964 + bec6409 commit e2bebf3

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
@@ -729,10 +729,20 @@ impl String {
729729
/// Note that this will drop any excess capacity.
730730
#[unstable(feature = "box_str",
731731
reason = "recently added, matches RFC")]
732-
pub fn into_boxed_slice(self) -> Box<str> {
732+
pub fn into_boxed_str(self) -> Box<str> {
733733
let slice = self.vec.into_boxed_slice();
734734
unsafe { mem::transmute::<Box<[u8]>, Box<str>>(slice) }
735735
}
736+
737+
/// Converts the string into `Box<str>`.
738+
///
739+
/// Note that this will drop any excess capacity.
740+
#[unstable(feature = "box_str",
741+
reason = "recently added, matches RFC")]
742+
#[deprecated(since = "1.4.0", reason = "renamed to `into_boxed_str`")]
743+
pub fn into_boxed_slice(self) -> Box<str> {
744+
self.into_boxed_str()
745+
}
736746
}
737747

738748
impl FromUtf8Error {

src/libcollectionstest/str.rs

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

12101210
#[test]
12111211
fn test_box_slice_clone() {
12121212
let data = String::from("hello HELLO hello HELLO yes YES 5 中ä华!!!");
1213-
let data2 = data.clone().into_boxed_slice().clone().into_string();
1213+
let data2 = data.clone().into_boxed_str().clone().into_string();
12141214

12151215
assert_eq!(data, data2);
12161216
}

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)