wstr: implement ToOwned::clone_into for WStr

This commit is contained in:
Moulins 2022-08-12 09:59:18 +02:00 committed by Mike Welsh
parent 2e255a5bba
commit a678a39e85
1 changed files with 13 additions and 0 deletions

View File

@ -284,6 +284,14 @@ impl WString {
})
}
/// Truncates this `WString`, removing all contents.
pub fn clear(&mut self) {
// SAFETY: 0 is always a valid length.
unsafe {
self.meta = ptr::WStrMetadata::new(0, self.meta.is_wide());
}
}
/// Appends a UTF-16 code unit to `self`.
///
/// This will convert this `WString` into its wide form if necessary.
@ -413,6 +421,11 @@ impl ToOwned for WStr {
buf.push_str(self);
buf
}
fn clone_into(&self, target: &mut Self::Owned) {
target.clear();
target.push_str(self);
}
}
impl Deref for WString {