mirror of
https://github.com/rust-lang/rust
synced 2024-07-05 16:05:59 +00:00
Rollup merge of #126970 - DaniPopes:simplify-str-clone_into, r=cuviper
Simplify `str::clone_into` Removes an `unsafe` in favor of just using `String` methods.
This commit is contained in:
commit
2c228260dc
|
@ -206,15 +206,16 @@ fn borrow_mut(&mut self) -> &mut str {
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl ToOwned for str {
|
impl ToOwned for str {
|
||||||
type Owned = String;
|
type Owned = String;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_owned(&self) -> String {
|
fn to_owned(&self) -> String {
|
||||||
unsafe { String::from_utf8_unchecked(self.as_bytes().to_owned()) }
|
unsafe { String::from_utf8_unchecked(self.as_bytes().to_owned()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn clone_into(&self, target: &mut String) {
|
fn clone_into(&self, target: &mut String) {
|
||||||
let mut b = mem::take(target).into_bytes();
|
target.clear();
|
||||||
self.as_bytes().clone_into(&mut b);
|
target.push_str(self);
|
||||||
*target = unsafe { String::from_utf8_unchecked(b) }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user