diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2017-04-13 02:48:46 -0700 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2017-04-18 21:02:18 -0700 |
| commit | 295bcdb715871ef3ba0258c75dad885b7315a162 (patch) | |
| tree | 55cd65b380897d4c742b5b1073da93fd3a1cf5da /src/libstd/ffi | |
| parent | 9f2abadca2d065bf81772cb84981d0a22d8e98b3 (diff) | |
| download | rust-295bcdb715871ef3ba0258c75dad885b7315a162.tar.gz rust-295bcdb715871ef3ba0258c75dad885b7315a162.zip | |
Override ToOwned::clone_into for Path and OsStr
The only non-overridden one remaining is the CStr impl, which cannot be optimized as doing so would break CString's second invariant.
Diffstat (limited to 'src/libstd/ffi')
| -rw-r--r-- | src/libstd/ffi/os_str.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index bf3f41b13c1..b90192dd8af 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -677,7 +677,13 @@ impl Borrow<OsStr> for OsString { #[stable(feature = "rust1", since = "1.0.0")] impl ToOwned for OsStr { type Owned = OsString; - fn to_owned(&self) -> OsString { self.to_os_string() } + fn to_owned(&self) -> OsString { + self.to_os_string() + } + fn clone_into(&self, target: &mut OsString) { + target.clear(); + target.push(self); + } } #[stable(feature = "rust1", since = "1.0.0")] @@ -863,4 +869,14 @@ mod tests { let boxed = <Box<OsStr>>::default(); assert!(boxed.is_empty()); } + + #[test] + fn test_os_str_clone_into() { + let mut os_string = OsString::with_capacity(123); + os_string.push("hello"); + let os_str = OsStr::new("bonjour"); + os_str.clone_into(&mut os_string); + assert_eq!(os_str, os_string); + assert!(os_string.capacity() >= 123); + } } |
