mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Simplify str::clone_into
Removes an `unsafe` in favor of just using `String` methods.
This commit is contained in:
parent
c290e9de32
commit
d5ff4f4f65
@ -206,15 +206,16 @@ impl BorrowMut<str> for String {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl ToOwned for str {
|
||||
type Owned = String;
|
||||
|
||||
#[inline]
|
||||
fn to_owned(&self) -> String {
|
||||
unsafe { String::from_utf8_unchecked(self.as_bytes().to_owned()) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn clone_into(&self, target: &mut String) {
|
||||
let mut b = mem::take(target).into_bytes();
|
||||
self.as_bytes().clone_into(&mut b);
|
||||
*target = unsafe { String::from_utf8_unchecked(b) }
|
||||
target.clear();
|
||||
target.push_str(self);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user