From 295bcdb715871ef3ba0258c75dad885b7315a162 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Thu, 13 Apr 2017 02:48:46 -0700 Subject: 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. --- src/libstd/ffi/os_str.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/libstd/ffi') 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 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 = >::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); + } } -- cgit 1.4.1-3-g733a5