-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add String::into_boxed_slice and Box<str>::into_string #26931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
@@ -1746,6 +1746,14 @@ fn to_uppercase() { | |||
assert_eq!("aéDžßfiᾀ".to_uppercase(), "AÉDŽSSFIἈΙ"); | |||
} | |||
|
|||
#[test] | |||
fn test_into_string() { | |||
// The only way to acquite a Box<str> in the first place is through a String, so just |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
acquite acquire
f8b9f64
to
17c914e
Compare
Responded to feedback in the newest commit. Updated a typo, and use |
@@ -741,6 +742,24 @@ impl String { | |||
string: self_ptr, | |||
} | |||
} | |||
|
|||
/// Converts the string into Box<str>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: backticks
1520bc0
to
3509b13
Compare
Thanks! @bors r+ |
📌 Commit 3509b13 has been approved by |
|
||
unsafe { | ||
String::from_raw_parts(Box::into_raw(self) as *mut u8, len, len) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be best implemented compositionally with a transmute, <[_]>::into_vec
plus String::from_utf8_unchecked
, that way there's no need to worry about the raw parts being exactly what we want, and there's exactly one point of Box<[T]>
to Vec<T>
(into_vec
)
@bors: r- (just some minor nits about the implementation, but follow ups are hard...) |
Implements merged RFC 1152. Closes rust-lang#26697.
@alexcrichton updated with suggested refactor - I actually thought of doing it that way the first time, but decided on the more manual route to avoid transmuting |
Implements merged RFC 1152. Closes #26697.
I want to rename this method, see Rename String::into_boxed_slice -> into_boxed_str #27696 |
Implements merged RFC 1152.
Closes #26697.